<?php

ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
ini_set('memory_limit', '512M');
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\cache\advertisement\CNewUserProfile;
use Biz\cache\bizAd\CtrWhite;
use Biz\cache\brand\BrandResumeInfo;
use Biz\cache\ShopClassifies as cShopClassifies;
use Biz\cache\wiki\JdUnionUrl;
use Biz\cache\wiki\ObjRelateWiki as cObjRelateWiki;
use Biz\cache\wiki\TbkGoods;
use Biz\cache\wiki\TopicWiki as cTopicWiki;
use Biz\cache\wiki\WikiRanking as cacheWikiRanking;
use Biz\model\Album\AlbumListModel;
use Biz\model\Album\AlbumRelateTagsModel;
use Biz\model\bigData\UserConsumeDecisionScore;
use Biz\model\bizAd\AdPrice as mAdPrice;
use Biz\model\brand\CustomCategoryWiki as mCustomCategoryWiki;
use Biz\model\ShopCategoryClassify as mShopCategoryClassify;
use Biz\model\wiki\ObjRelateWiki as mObjRelateWiki;
use Biz\model\wiki\Wiki as mWiki;
use Biz\model\wiki\WikiRankingData;
use Biz\model\wiki\WikiRankingHot;
use Biz\module\Classes\wiki\Wiki as clsWiki;
use Biz\scraper\GoodsInfo as scraperGoodsInfo;
use Biz\service\bizAd\AdPlan;
use Biz\service\brand\Brand as BrandService;
use Biz\service\brand\BrandShop;
use Biz\service\ShopClassify;
use Biz\service\ShopClassify as sShopClassify;
use Biz\service\wiki\AdmWiki;
use Biz\service\wiki\ObjRelateWiki as sObjRelateWiki;
use Biz\service\wiki\Wiki;
use Biz\tools\BizUrl;
use Biz\tools\RealUrl;
use Biz\tools\TbkUnion;
use Doraemon\cache\PhotoCounter;
use Doraemon\cache\PositionModule\UserProfile;
use Doraemon\cache\UserCounter;
use Doraemon\model\Category as mCategory;
use Doraemon\model\Es\Photo;
use Doraemon\model\Live\LiveUserKeepTimeTop3;
use Doraemon\model\Member;
use Doraemon\model\MemberExtendInfo;
use Doraemon\service\Article as sArticle;
use Doraemon\service\Format\Blank\HandleBlank;
use Doraemon\service\Member\PhoneCrypto;
use Doraemon\service\Photos as sPhotos;
use Doraemon\service\position\PositionApi;
use Doraemon\service\statSign\Basic as basicStatSign;
use Doraemon\service\User;
use Doraemon\service\UserPortrait\UserPortraitApi;
use Doraemon\tools\BlockType;
use Doraemon\tools\IdParse;
use Doraemon\tools\ImgUrl;
use Doraemon\tools\ImgUrl as toolImgUrl;
use Doraemon\tools\Sms;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use hhz\constant\redis\redisKeys;
use Hhz\Redis\otherRedis;
use Medoo\Medoo;
use Biz\service\wikiRanking\Ranking;
use Doraemon\model\Phone as PhoneModel;
use hhz\constant\basic\UserExtendPhoneScene;
use Biz\model\activity\ActivityAwardDelivery;
use Biz\model\activity\ActivityBasic;
use Biz\cache\wiki\WikiRanking as WikiRankingCache;
use Biz\model\wiki\WikiRankingPublicPraise;
use Biz\model\wiki\WikiRankingBrand;
use Biz\cache\wiki\UserRecommendWikiRanking;
use Doraemon\cache\UserClient;
use Doraemon\service\Elasticsearch\Photo as esPhotoService;
use Doraemon\tools\Curl;
use Doraemon\model\ConstructionPurchase\ConstructionCategory;
use Doraemon\service\ConstructionPurchase\Construction;

$objType = 1;
$objIds = ['0009wlf0000booq1', '0009wko0000boo98', '0009wk10000bonyd', '0009wi90000bonyd', '000113s0100bomke'];
$objType = 2;
$objIds = ['0000pcv0500booq1', '0000pcj0500bomke'];
$res = \Biz\service\wiki\ObjRelateWiki::getRelateListByObjIds($objType, $objIds);
var_dump($res);
die;

$res = \Biz\cache\wiki\ObjRelateWiki::getObjCaches(1, ['0009wlf0000booq1', '0009wko0000boo98', '0009wk10000bonyd']);
var_dump($res);
die;

$res = \Biz\cache\wiki\CategoryWiki::getWikiInfoByCateId(535);
var_dump($res);
$res = \Biz\cache\wiki\CategoryWiki::getWikiInfoByCateId(1796);
var_dump($res);
die;
$res = \Biz\cache\wiki\CategoryWiki::getBrandInfosByIds([2631, 3349, 3082]);
var_dump($res);
die;

$res = \Biz\model\brandRights\BrandRightsSource::select(['id', 'rights_name'], ['rights_type' => \Biz\model\brandRights\BrandRightsSource::RIGHTS_TYPE_OPEN]);
var_dump($res);

foreach ($res as $row) {
    $allList = \Biz\model\brandRights\BrandRightsAll::select('*', ['rights_source_id' => $row['id'], 'rights_name' => $row['rights_name'], 'rights_status' => 1]);
    foreach ($allList as $item) {
        $endTime = $item['end_time'];
        $day = date('m-d', $endTime);
        $time = date('H:i:s', $endTime);
        $endTimeNew = '2030-' . $day . " " . $time;
        var_dump('id:' . $item['id'] . '#end_time:' . date('Y-m-d H:i:s', $item['end_time']) . '>>>>' . $endTimeNew);

        \Biz\model\brandRights\BrandRightsAll::update(['end_time' => strtotime($endTimeNew)], [
            'end_time' => $endTime, 'id' => $item['id'], 'rights_source_id' => $row['id']
        ]);
        var_dump('update sql>>', \Biz\model\brandRights\BrandRightsAll::log());
    }
}
die;

$categoryList = ConstructionCategory::selectListByWhere(['pid[>]' => 0, 'status' => ConstructionCategory::STATUS_NORMAL]);
foreach ($categoryList as $row) {
    $linkParams = $row['link']['link_params'] ?? '';
    $linkParam = $linkParams ? json_decode($linkParams, true) : [];
    $url = $linkParam['url'] ?? '';
    if ($url) {
        $result = Curl::Request('GET', $url);
        $html = $result['data'];
        $pattern = '/"noteIdList":s*"([^"]+)/';
        preg_match($pattern, $html, $matches);
        if ($matches && $matches[1]) {
            $keywords = $matches[1];
            var_dump($url . '#keywords:' . $keywords);
            $keywords = explode(',', $keywords);
            Construction::getLegoRecommendNoteIds($keywords);
        }
    }
}

$res = \Biz\cache\wiki\ShortTitle::getMulti([1262, 17843, 77502, 77213, 73941, 58378, 53613]);
var_dump($res);
die;

$topicId = 1511;
var_dump(cTopicWiki::getWikisNum($topicId));
$topicId = 1066;
var_dump(cTopicWiki::getWikisNum($topicId));
die;
$response = cTopicWiki::getPagedList($topicId, 1, 20);
var_dump($response);

die;


exportNote();
die;
function exportNote()
{
    $where = [
        'text_remark' => '蒸烤箱',
        'addtime[>=]' => strtotime('2023-01-01'),
        'addtime[<=]' => strtotime('2023-06-30'),
        'LIMIT' => [0, 1500]
    ];
    $esResult = Photo::getNoteListByParams($where, 'id');
    $noteIds = array_column($esResult['rows'], 'id');
    $photoInfos = sPhotos::getPhotos($noteIds);
    $uids = array_column($photoInfos, 'uid');
    $userInfos = Member::getUserInfoByIds($uids);
    $userInfos = array_column($userInfos, null, 'uid');
    $count = PhotoCounter::getMulti($noteIds);
    $filePath = 'noteInfos.csv';
    $fp = fopen($filePath, 'w');
    fputcsv($fp, ['note Id', 'uid', '昵称', '用户身份', '正文', '点赞数', '评论数', '收藏数']);
    foreach ($photoInfos as $noteId => $photoInfo) {
        $nick = $userInfos[$photoInfo['uid']]['nick'];
        $type = $userInfos[$photoInfo['uid']]['type'];
        $type = Member::$typeDesc[$type] ?? '';
        fputcsv($fp, [
            $photoInfo['id'],
            $photoInfo['uid'],
            $nick,
            $type,
            $photoInfo['remark'],
            $count[$noteId]['like'],
            $count[$noteId]['favorite'],
            $count[$noteId]['comments'],
        ]);
    }
    fclose($fp);
}

var_dump(date('Ym', strtotime('-12 month')));
die;

var_dump(\Biz\cache\brand\BrandBeLikedache::muilteGetUserLike([1389, 1144, 2580]));

$res = \Biz\cache\wiki\LastRelateUids::getPagedList(297216, 1, 20);
var_dump($res);

$res = \Biz\cache\wiki\LastRelateUids::getPagedList(129878, 1, 20);
var_dump($res);

$res = \Biz\cache\wiki\LastRelateUids::getPagedList(118436, 1, 20);
var_dump($res);
die;

$noteLists = (new esPhotoService)->getPhotosIdByLightTopic("一人一个装修经验", 1582647, 1, 1, 20);
die;


$url = 'https://chaoshi.detail.tmall.com/item.htm?id=642660100138';
$res = Wiki::getWikiByLink($url);
var_dump($res);
die;
$uid = 1582647;
$res = \Biz\cache\brand\BrandShowActivity::isLock($uid . '-blind-box', 2);
var_dump($res);
die;

//rankingCache();
//die;

function brandInEndTime()
{
    $today = date('Y-m-d');
    $where = [
        'type' => \Biz\model\brandAccount\BrandAccountInfo::ACCOUNT_TYPE_BRAND,
        'account_status' => \Biz\model\brandAccount\BrandAccountInfo::ACCOUNT_STATUS_USED,
    ];
    $list = \Biz\model\brandAccount\BrandAccountInfo::select('*', $where);
    foreach ($list as $row) {
        $inEndTime = $row['in_end_time'];
        $day = date('m-d', strtotime($inEndTime));
        $inEndTimeNew = '2030-' . $day;
        \Biz\model\brandAccount\BrandAccountInfo::updateData(['in_end_time' => $inEndTimeNew], ['id' => $row['id'], 'in_end_time' => $inEndTime]);
        var_dump($inEndTime . '#' . $inEndTimeNew);
    }
    die;
}


//$uid = 1582647;
//$verList = UserClient::verList($uid);
//$verList = array_keys($verList);
//var_dump($verList);
//rsort($verList);
//var_dump($verList);
//if (count($verList) > 3) {
//    //剔除历史版本
//    array_map(function ($v) use ($uid) {
//        UserClient::verDel($uid, $v);
//    }, $verList);
//}
//die;


//$verList = UserClient::verList2(19997);
//var_dump($verList);
//die;
$maxUid = 17000000;

$startTime = time();
$page = $argv[1] ?? 1;

$startUid = 850000 * ($page - 1);
$endUid = 850000 * $page;
$lastUid = 0;
$offset = 50000;
$num = ceil(850000 / $offset);
$redis = new otherRedis(redisKeys::KEY_B_OTHER_USER_CLIENT_VER);
for ($i = 0; $i < $num; $i++) {
    $start = $startUid + ($i * $offset);
    $end = $start + $offset;
    var_dump($start . ':' . $end);
    if ($end <= $endUid) {
        addUserClient($redis, $start, $end);
    }
    sleep(1);
}
$endTime = time();
var_dump('耗时#' . ($endTime - $startTime) . '秒');
die;

function addUserClient($redis, $start, $end)
{
    var_dump('查询' . $start . '至' . $end . '之间的uid');
    $uids = Member::selectByWhere(['uid[>]' => $start, 'uid[<=]' => $end], 'uid');
    var_dump(Member::log(), count($uids));
    foreach ($uids as $uid) {
        $key = redisKeys::KEY_B_OTHER_USER_CLIENT_VER . ':' . $uid;
        $hasVerList = $redis->hgetall($key);
        if (!$hasVerList) {
            var_dump('处理uid 缓存:' . $key);
            $verList = UserClient::verList($uid);
            if ($verList) {
                if (count($verList) <= 3) {
                    $redis->pipeline(function ($pipe) use ($redis, $uid, $key, $verList) {
                        foreach ($verList as $ver => $time) {
                            $pipe->hset($key, $ver, $time);
                        }
                    });
                }
            }
        }
    }
}

Ranking::getRankingIdsByUserAction(1582647);
$list = UserRecommendWikiRanking::getUserActionCate(1582647);
var_dump($list);
die;

Ranking::getHotRankingList();
$list = UserRecommendWikiRanking::getHotRanking(Ranking::getRankingDay());
var_dump($list);
die;

UserRecommendWikiRanking::addRankingBrands(1582647, 125, [
    'brand' => [
        "霜山shimoyama",
        "宜家家居 IKEA",
        "Panasonic松下住空间",
        "原始原素家居",
        "CHONG翀",
        "二黑木作",
        "科勒 KOHLER",
        "EraClean世净",
        "云物生活",
        "井井标记"
    ],
    "ranking_name" => "餐厨收纳"
]);
$data = UserRecommendWikiRanking::getRankingBrand(1582647);
var_dump($data);
die;
UserRecommendWikiRanking::addRankingId(1582647, 4);
UserRecommendWikiRanking::addRankingIds(1582647, [2, 3, 5, 6]);
var_dump(UserRecommendWikiRanking::getCount(1582647));
var_dump(UserRecommendWikiRanking::getRankingId(1582647));
die;

rankingCache();
die;

$res = \Biz\service\wiki\RelatePhoto::getWikiListByPhotoIds(['0009j6h00001386h', '0009j7h00001386h'], Wiki::FIELDS_GROUP_MASONRY_LIST);
var_dump(json_encode($res));
die;

$res = Wiki::getWikiList([4, 5], 1582647, Wiki::FIELDS_GROUP_MASONRY_LIST);
var_dump(json_encode($res));
die;

var_dump(WikiRankingCache::getHotRankingByBasicIds(20230503, [4]));
die;
WikiRankingCache::addBasicWikiHotRanking(20230503, 4, 1, 4);

die;

function rankingCache()
{
    $day = Ranking::getRankingDay();
    //榜单数据列表
    resetWikiRankingList();
    var_dump(WikiRankingCache::getWikiRankingList([125, 12, 13, 77]));

    //榜单数据
    setWikiRankingDataIds($day);

    //上榜的榜单数据
    Ranking::setShowRankingIds();
    var_dump(WikiRankingCache::getShowRankingIds($day, 1));
    var_dump(WikiRankingCache::getShowRankingIds($day, 2));
    var_dump(WikiRankingCache::getShowRankingIds($day, 3));

    //榜单封面图
    $hotCoverKeys = WikiRankingCache::keys('wiki_ranking_hot_cover_' . $day . '_*');
    foreach ($hotCoverKeys as $key) {
        $keyArr = explode('_', $key);
        $rankId = $keyArr[5];
        $data = WikiRankingCache::get($key);
        $data = json_decode($data, true);
        WikiRankingCache::setHotRankingCover($day, $rankId, $data['hot_ranking_id'], $data['cover_img']);
        var_dump(WikiRankingCache::getHotRankingCover($day, $rankId));
    }


    //品牌榜缓存数据
    $list = WikiRankingBrand::select('*', ['ranking_day' => $day, 'ranking_state' => WikiRankingBrand::RANKING_STATE_SHOW]);
    foreach ($list as $row) {
        WikiRankingCache::addBrandRanking($day, $row['basic_id'], $row['top_num'], $row['ranking_id']);
        var_dump(WikiRankingCache::getBrandRankingByBrandIds($day, [$row['basic_id']]));
    }

    //口碑榜缓存数据
    $list = WikiRankingPublicPraise::select('*', ['ranking_day' => $day, 'ranking_state' => WikiRankingPublicPraise::RANKING_STATE_SHOW]);
    foreach ($list as $row) {
        WikiRankingCache::addBasicWikiPublicPraiseRanking($day, $row['basic_id'], $row['top_num'], $row['ranking_id']);
        var_dump(WikiRankingCache::getPublicPraiseRankingByBasicIds($day, [$row['basic_id']]));
    }

    //热度榜缓存数据
    $hotList = WikiRankingHot::select('*', ['ranking_day' => $day, 'ranking_state' => WikiRankingHot::RANKING_STATE_SHOW]);
    foreach ($hotList as $row) {
        WikiRankingCache::addBasicWikiHotRanking($day, $row['basic_id'], $row['top_num'], $row['ranking_id']);
        var_dump(WikiRankingCache::getHotRankingByBasicIds($day, [$row['basic_id']]));
    }

    var_dump(WikiRankingCache::getHotRankingByBasicIds($day, [361377, 360996, 358321, 350472]));
    var_dump(WikiRankingCache::getPublicPraiseRankingByBasicIds($day, [81613, 355999, 111764, 123489]));
    var_dump(WikiRankingCache::getBrandRankingByBrandIds($day, [330897, 321809, 306162, 358875]));
}

$res = \Biz\module\Classes\wiki\Wiki::getWikiContentInfos([3, 1]);
var_dump($res);
die;

$res = \Biz\module\Classes\wiki\Wiki::getWikiBaseInfos([4, 5, 6, 1, 2, 3]);
var_dump($res);
die;


$res = \Biz\module\Classes\wiki\WikiBasic::getWikiBasicInfos([1, 2, 3, 4, 5, 6, 7, 8]);
var_dump($res);
die;


$res = \Doraemon\service\RecommendWikiCategory::getWikiCateGoryInfo(1582647, 825);
var_dump($res);
die;

\Doraemon\service\search\Schedule::buildWikiRankCache();

$res = \Doraemon\cache\WikiRanking\GoodsChannelWikiRanking::getList(2078, 0, 20);
var_dump($res);
die;

testGetRelatedWikiListByObjIds();
die;

\Doraemon\tools\HhzClient::setClientVersion('6.15.0');
$res = \Doraemon\service\Live\LiveChest::getWikiList([7664, 7674, 7656, 7649], 'list');
var_dump($res);
die;

$res = Wiki::getWikiListByBasicIds([7664, 7674, 7656, 7649]);
var_dump(json_encode($res));
die;

//$res=Wiki::getRecommendHot(1582647,1,20);
//var_dump(json_encode($res));
//die;

testGetWikiListByBasicIds();
die;


$str = '/Users/yiwan/data/wwwroot/g_biz/cli/Fix/tywFix.php';
$fileSize = filesize($str);
var_dump($fileSize);
die;

checkWikiCoverImage();
die;

function checkWikiCoverImage()
{
    //检查wiki封面图是否正常
    $filePath = '/tmp/notfoundWiki.csv';
    $fp = fopen($filePath, 'w');
    fputcsv($fp, ['wikiId', '渠道', '封面图', 'url']);
    $page = 1;
    $pageSize = 2000;
    $i = 0;
    do {
        $list = mWiki::selectByWhere([
            'status[!]' => mWiki::STATUS_DEL,
            'channel_spu_status' => 1,
            'cover_img[!]' => '',
            'LIMIT' => [($page - 1) * $pageSize, $pageSize]
        ], ['id', 'cover_img', 'channel', 'channel_type', 'channel_spu_id', 'channel_jump_params', 'channel_shop_id']);
        var_dump('检查第' . $page . '页' . $pageSize . '条');
        foreach ($list as $row) {
            $code = getHttpCode($row['cover_img']);
            if ($code != 200) {
                var_dump($row['id'] . '#' . $code . '#' . $row['cover_img']);
                $url = RealUrl::formatLink($row['channel_spu_id'], $row['channel_type'], $row['channel_jump_params'],
                    $row['channel_shop_id']);
                fputcsv($fp, [
                    $row['id'],
                    mWiki::CHANNEL_TYPE_MAP[$row['channel_type']],
                    $row['cover_img'],
                    $url
                ]);
                $i++;
            }
        }
        $page++;
    } while ($list);
    fclose($fp);
    var_dump('检查异常总共:' . $i . '条');
}

function getHttpCode($url)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_NOBODY, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //把数据存成字符串

    if (!curl_exec($curl)) {  //开始执行
        $code = 500;
    } else {
        $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    }

    curl_close($curl); //用完关掉

    return $code;
}


resetWikiRankingList();
die;


getPhotoUrls();
die;

function getPhotoUrls()
{

    $urlArr = [];
    $fileArr = [];
    $dirPath = '/Users/yiwan/Desktop/photosJson';

    if ($dir = opendir($dirPath)) {
        $i = 0;
        while (($file = readdir($dir)) !== false) {
            if (is_dir($dirPath . $file)) {
                var_dump("文件夹: $file");
            } else {
                var_dump("文件: $file");
                $fileArr[] = $file;
                $jsonStr = file_get_contents($dirPath . '/' . $file);
                if ($jsonStr) {
                    $photos = json_decode($jsonStr, true);
                    foreach ($photos['photos'] as $photo) {
                        $path = parse_url($photo['download_url'], PHP_URL_PATH);
                        $index = strrpos($path, '/');
                        $fileName = substr($path, $index + 1);
                        $photoFile = '/Users/yiwan/Desktop/0402_photos/' . $fileName;
                        download($photo['download_url'], $photoFile);
                    }
                }
            }
        }
    }
    var_dump($urlArr);

    file_put_contents("/Users/yiwan/Desktop/photosUrls.json", json_encode($urlArr));
}

function download($url, $filename)
{
    var_dump('下载图片#file:' . $filename . '#url:' . $url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
    $file = curl_exec($ch);
    curl_close($ch);
    $resource = fopen($filename, 'a');
    fwrite($resource, $file);
    fclose($resource);
    return $filename;
}

testGetWikiInfo();
die;

$res = \Biz\service\wiki\ObjRelateWiki::getWikiListByObjIds(['0009wlf0000booq1'], 1);
var_dump(json_encode($res));
die;

$res = \Biz\service\wiki\RelatePhoto::getRelateWikiImgByNoteIds(['0009wlf0000booq1']);
var_dump(json_encode($res));
die;

$res = \Biz\service\wiki\RelatePhoto::getWikiListByPhotoIds(['0009wlf0000booq1']);
var_dump(json_encode($res));
die;

$result = sObjRelateWiki::getRelateWikiList("000013602000097p", mObjRelateWiki::OBJ_TYPE_GUIDE, [], 1582647);
var_dump(json_encode($result));
die;

$result = sObjRelateWiki::getRelateWikiList("000113s0100bomke", mObjRelateWiki::OBJ_TYPE_ARTICLE, [], 1582647);
var_dump(json_encode($result));
die;

$result = sObjRelateWiki::getRelateWikiList("0009wlf0000booq1", mObjRelateWiki::OBJ_TYPE_NOTE, [], 1582647);
var_dump(json_encode($result));
die;


testGetWikiInfo();
sleep(3);
testGetRelatedWikiListByObjId();
sleep(3);
testGetRelatedWikiListByObjIds();
sleep(3);
testGetRelatedWikiListByRelObjIdsRequest();
die;

function testGetWikiInfo()
{
    //grpc 调用
    $wikiGrpcClient = \Wiki\GrpcClient::getInstance();
    $aRet = $wikiGrpcClient->getWikiInfo([
        "wikiIds" => [4],
        "fieldsGroup" => "list",
        "uid" => 11941,
    ]);
    var_dump(json_encode($aRet['result']));
    return

        //http 调用
        $wikiHttpClient = \Wiki\HttpClient::getInstance();
    $aRet = $wikiHttpClient->getWikiInfo([
        "wikiIds" => [4],
        "fieldsGroup" => "masonry_list",
        "uid" => 11941,
    ]);
    var_dump(json_encode($aRet['list']));
    die;
}

function testGetWikiListByBasicIds()
{
    //grpc 调用
    $wikiGrpcClient = \Wiki\GrpcClient::getInstance();
    $aRet = $wikiGrpcClient->getWikiListByBasicIds([
        "basicIds" => [7674, 7664, 7656, 7649],
        "fieldsGroup" => "masonry_list",
        "uid" => 11941,
    ]);
    var_dump(json_encode($aRet));
    die;

    //http 调用
    $wikiHttpClient = \Wiki\HttpClient::getInstance();
    $aRet = $wikiHttpClient->getWikiListByBasicIds([
        "basicIds" => [4],
        "fieldsGroup" => "masonry_list",
        "uid" => 11941,
    ]);
    var_dump($aRet);
}

/**
 *
 * @return void
 */
function testGetHotWikiList()
{
    //grpc 调用
    $wikiGrpcClient = \Wiki\GrpcClient::getInstance();
    $aRet = $wikiGrpcClient->getHotWikiList([
        "uid" => 11941,
        "page" => 1,
        "pageSize" => 20,
        "fieldsGroup" => "masonry_list",
    ]);
    var_dump(json_encode($aRet));
    die;

    //http 调用
    $wikiHttpClient = \Wiki\HttpClient::getInstance();
    $aRet = $wikiHttpClient->getHotWikiList([
        "uid" => [4],
        "page" => 1,
        "pageSize" => 20,
        "fieldsGroup" => "masonry_list",
    ]);
    var_dump($aRet);
}


/**
 * 单个查询一个内容关联的wiki列表（note、blank、article、guide）
 * @return void
 */
function testGetRelatedWikiListByObjId()
{
    //grpc 调用
    $wikiGrpcClient = \Wiki\GrpcClient::getInstance();
    $aRet = $wikiGrpcClient->getRelatedWikiListByObjId([
        "objId" => "0009wlf0000booq1",
        "objType" => 1,
        "uid" => 11941,
        "fieldsGroup" => "list",
    ]);
    var_dump(json_encode($aRet['result']));
    return
        //http 调用
        $wikiHttpClient = \Wiki\HttpClient::getInstance();
    $aRet = $wikiHttpClient->getRelatedWikiListByObjId([
        "wikiIds" => [4],
        "fieldsGroup" => "masonry_list",
        "uid" => 11941,
    ]);
    var_dump($aRet);
}

/**
 * 批量查询多个内容关联的wiki列表（多个内容类型保持一致 note、blank；）
 * @return void
 */
function testGetRelatedWikiListByObjIds()
{
    //grpc 调用
    $wikiGrpcClient = \Wiki\GrpcClient::getInstance();
    $aRet = $wikiGrpcClient->getRelatedWikiListByObjIds([
        "objIds" => ["0009wlf0000booq1", "0009wko0000boo98"],
        "objType" => 1,
        "fieldsGroup" => "list",
        "uid" => 11941,
    ]);
    var_dump(json_encode($aRet['result']));
    return
        //http 调用
        $wikiHttpClient = \Wiki\HttpClient::getInstance();
    $aRet = $wikiHttpClient->getRelatedWikiListByObjIds([
        "objIds" => ["0009wlf0000booq1", "0009wko0000boo98"],
        "objType" => 1,
        "fieldsGroup" => "list",
        "uid" => 11941,
    ]);
    var_dump($aRet);
}

/**
 * 按一个内容下多个关联的图片查询图片所关联的wiki列表
 * @return void
 */
function testGetRelatedWikiListByRelObjIdsRequest()
{
    //grpc 调用
    $wikiGrpcClient = \Wiki\GrpcClient::getInstance();
    $aRet = $wikiGrpcClient->getRelatedWikiListByRelObjIds([
        "objId" => "0009wlf0000booq1",//note id
        "objType" => 1,
        "relObjIds" => ["436b820u01qc0ax00rr6zrubooq1", "436b820u01qc0ax00rr6zrubooq1", "436b820u01qc0ax00rr6zrubooq1"],//图片id
        "relObjType" => 1,
        "fieldsGroup" => "list",
        "uid" => 11941,
    ]);
    var_dump(json_encode($aRet['result']));
    return
        //http 调用
        $wikiHttpClient = \Wiki\HttpClient::getInstance();
    $aRet = $wikiHttpClient->getRelatedWikiListByRelObjIds([
        "objId" => "0009wlf0000booq1",//note id
        "objType" => 1,
        "relObjIds" => ["436b820u01qc0ax00rr6zrubooq1", "436b820u01qc0ax00rr6zrubooq1", "436b820u01qc0ax00rr6zrubooq1"],//图片id
        "relObjType" => 1,
        "fieldsGroup" => "list",
        "uid" => 11941,
    ]);
    var_dump($aRet);
}


$ids = \Biz\model\brand\ShopAddres::select('phone_encrypt_id', ['shop_status' => 1, 'brand_id' => 309]);
$phones = BrandShop::batchGetDecryptPhones($ids);
var_dump(json_encode($phones));


$rankingList = Ranking::getRecommendRanking(12945966);
var_dump(json_encode($rankingList, JSON_UNESCAPED_UNICODE));
die;

encryptYouZanOrderReceiverPhone(1);
die;

encryptBlindBoxConsigneePhone(1);
die;

$getPhone = PhoneModel::getExtendPhone(79, UserExtendPhoneScene::BRAND_SHOP_INFO_PHONE);
var_dump($getPhone);
die;

encryptBrandShopInfoPhone(1);
die;

encryptBrandAuthInfoPhone(1);
die;

encryptBrandRightsLevelInfoPhone();
die;

die;
encryptBrandApplyInfoPhone();
die;

function encryptYouZanOrderReceiverPhone($type = 1)
{
    //type,1:给原始手机号加密，并记录加密id 2：给原始手机号打码
    if ($type == 1) {
        //给原始手机号加密，并记录加密id
        $list = \Biz\model\SuperSubsidy\YouZanOrderInfo::select('*', ['receiver_tel_encrypt_id' => 0]);
        foreach ($list as $row) {
            if ($row['receiver_tel']) {
                $encryptPhoneId = PhoneModel::addExtendPhone($row['receiver_tel'], UserExtendPhoneScene::YOUZAN_ORDER_RECEIVER_PHONE);
                if (!$encryptPhoneId) {
                    var_dump('加密失败', ['id' => $row['id'], 'receiver_tel' => $row['receiver_tel'], 'receiver_tel_encrypt_id' => $encryptPhoneId]);
                    continue;
                }
                $getPhone = PhoneModel::getExtendPhone($encryptPhoneId, UserExtendPhoneScene::YOUZAN_ORDER_RECEIVER_PHONE);
                if ($row['receiver_tel'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'receiver_tel' => $row['receiver_tel'], 'receiver_tel_encrypt_id' => $encryptPhoneId, 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'receiver_tel_uniq' => \Biz\service\SuperSubsidy\YouZanOrder::getReciverTelUniq($row['receiver_tel']),
                    'receiver_tel_encrypt_id' => $encryptPhoneId,
                ];
                \Biz\model\SuperSubsidy\YouZanOrderInfo::update($data, ['id' => $row['id'], 'receiver_tel' => $row['receiver_tel']]);
            }
        }
    } else if ($type == 2) {
        //给原始手机号打码
        $list = \Biz\model\SuperSubsidy\YouZanOrderInfo::select('*', ['receiver_tel_encrypt_id[>]' => 0]);
        foreach ($list as $row) {
            if ($row['receiver_tel']) {
                $getPhone = PhoneModel::getExtendPhone($row['receiver_tel_encrypt_id'], UserExtendPhoneScene::YOUZAN_ORDER_RECEIVER_PHONE);
                if ($row['receiver_tel'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'receiver_tel' => $row['receiver_tel'], 'receiver_tel_encrypt_id' => $row['receiver_tel_encrypt_id'], 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'receiver_tel' => PhoneCrypto::mask($row['receiver_tel'])
                ];
                \Biz\model\SuperSubsidy\YouZanOrderInfo::update($data, ['id' => $row['id'], 'receiver_tel' => $row['receiver_tel']]);
            }
        }
    }
}


function encryptBlindBoxConsigneePhone($type = 1)
{
    //type,1:给原始手机号加密，并记录加密id 2：给原始手机号打码
    if ($type == 1) {
        //给原始手机号加密，并记录加密id
        $list = \Biz\model\brandActivity\BlindBoxLotteryConsignee::select('*', ['consignee_mobile_encrypt_id' => 0]);
        foreach ($list as $row) {
            if ($row['consignee_mobile']) {
                $encryptPhoneId = PhoneModel::addExtendPhone($row['consignee_mobile'], UserExtendPhoneScene::BLIND_BOX_LOTTERY_PHONE);
                if (!$encryptPhoneId) {
                    var_dump('加密失败', ['id' => $row['id'], 'consignee_mobile' => $row['consignee_mobile'], 'consignee_mobile_encrypt_id' => $encryptPhoneId]);
                    continue;
                }
                $getPhone = PhoneModel::getExtendPhone($encryptPhoneId, UserExtendPhoneScene::BLIND_BOX_LOTTERY_PHONE);
                if ($row['consignee_mobile'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'consignee_mobile' => $row['consignee_mobile'], 'consignee_mobile_encrypt_id' => $encryptPhoneId, 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'consignee_mobile_encrypt_id' => $encryptPhoneId,
                ];
                \Biz\model\brandActivity\BlindBoxLotteryConsignee::update($data, ['id' => $row['id'], 'consignee_mobile' => $row['consignee_mobile']]);
            }
        }
    } else if ($type == 2) {
        //给原始手机号打码
        $list = \Biz\model\brandActivity\BlindBoxLotteryConsignee::select('*', ['consignee_mobile_encrypt_id[>]' => 0]);
        foreach ($list as $row) {
            if ($row['consignee_mobile']) {
                $getPhone = PhoneModel::getExtendPhone($row['consignee_mobile_encrypt_id'], UserExtendPhoneScene::BLIND_BOX_LOTTERY_PHONE);
                if ($row['consignee_mobile'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'consignee_mobile' => $row['consignee_mobile'], 'consignee_mobile_encrypt_id' => $row['consignee_mobile_encrypt_id'], 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'consignee_mobile' => PhoneCrypto::mask($row['consignee_mobile'])
                ];
                \Biz\model\brandActivity\BlindBoxLotteryConsignee::update($data, ['id' => $row['id'], 'consignee_mobile' => $row['consignee_mobile']]);
            }
        }
    }
}

function encryptBrandApplyInfoPhone($type = 1)
{
    //type,1:给原始手机号加密，并记录加密id 2：给原始手机号打码
    if ($type == 1) {
        //给原始手机号加密，并记录加密id
        $list = \Biz\model\brand\BrandApplyInfo::select('*', ['phone_encrypt_id' => 0]);
        foreach ($list as $row) {
            if ($row['phone']) {
                $encryptPhoneId = PhoneModel::addExtendPhone($row['phone'], UserExtendPhoneScene::BRAND_APPLY_INFO_PHONE);
                if (!$encryptPhoneId) {
                    var_dump('加密失败', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $encryptPhoneId]);
                    continue;
                }
                $getPhone = PhoneModel::getExtendPhone($encryptPhoneId, UserExtendPhoneScene::BRAND_APPLY_INFO_PHONE);
                if ($row['phone'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $encryptPhoneId, 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'phone_encrypt_id' => $encryptPhoneId,
                ];
                \Biz\model\brand\BrandApplyInfo::update($data, ['id' => $row['id'], 'phone' => $row['phone']]);
            }
        }
    } else if ($type == 2) {
        //给原始手机号打码
        $list = \Biz\model\brand\BrandApplyInfo::select('*', ['phone_encrypt_id[>]' => 0]);
        foreach ($list as $row) {
            if ($row['phone']) {
                $getPhone = PhoneModel::getExtendPhone($row['phone_encrypt_id'], UserExtendPhoneScene::BRAND_APPLY_INFO_PHONE);
                if ($row['phone'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $row['phone_encrypt_id'], 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'phone' => PhoneCrypto::mask($row['phone'])
                ];
                \Biz\model\brand\BrandApplyInfo::update($data, ['id' => $row['id'], 'phone' => $row['phone']]);
            }
        }
    }
}

function encryptBrandRightsLevelInfoPhone($type = 1)
{
    //type,1:给原始手机号加密，并记录加密id 2：给原始手机号打码
    if ($type == 1) {
        //给原始手机号加密，并记录加密id
        $list = \Biz\model\brandRights\BrandLevelRightsLeaveInfo::select('*', ['phone_encrypt_id' => 0]);
        foreach ($list as $row) {
            if ($row['phone']) {
                $encryptPhoneId = PhoneModel::addExtendPhone($row['phone'], UserExtendPhoneScene::BRAND_RIGHTS_LEAVE_INFO_PHONE);
                if (!$encryptPhoneId) {
                    var_dump('加密失败', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $encryptPhoneId]);
                    continue;
                }
                $getPhone = PhoneModel::getExtendPhone($encryptPhoneId, UserExtendPhoneScene::BRAND_RIGHTS_LEAVE_INFO_PHONE);
                if ($row['phone'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $encryptPhoneId, 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'phone_encrypt_id' => $encryptPhoneId,
                ];
                \Biz\model\brandRights\BrandLevelRightsLeaveInfo::update($data, ['id' => $row['id'], 'phone' => $row['phone']]);
            }
        }
    } else if ($type == 2) {
        //给原始手机号打码
        $list = \Biz\model\brandRights\BrandLevelRightsLeaveInfo::select('*', ['phone_encrypt_id[>]' => 0]);
        foreach ($list as $row) {
            if ($row['phone']) {
                $getPhone = PhoneModel::getExtendPhone($row['phone_encrypt_id'], UserExtendPhoneScene::BRAND_RIGHTS_LEAVE_INFO_PHONE);
                if ($row['phone'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $row['phone_encrypt_id'], 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'phone' => PhoneCrypto::mask($row['phone'])
                ];
                \Biz\model\brandRights\BrandLevelRightsLeaveInfo::update($data, ['id' => $row['id'], 'phone' => $row['phone']]);
            }
        }
    }
}

function encryptBrandAuthInfoPhone($type = 1)
{
    //type,1:给原始手机号加密，并记录加密id 2：给原始手机号打码
    if ($type == 1) {
        //给原始手机号加密，并记录加密id
        $list = \Biz\model\brandAccount\BrandAccountAuth::select('*', ['phone_encrypt_id' => 0]);
        foreach ($list as $row) {
            if ($row['phone']) {
                $encryptPhoneId = PhoneModel::addExtendPhone($row['phone'], UserExtendPhoneScene::BRAND_AUTH_INFO_PHONE);
                if (!$encryptPhoneId) {
                    var_dump('加密失败', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $encryptPhoneId]);
                    continue;
                }
                $getPhone = PhoneModel::getExtendPhone($encryptPhoneId, UserExtendPhoneScene::BRAND_AUTH_INFO_PHONE);
                if ($row['phone'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $encryptPhoneId, 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'phone_encrypt_id' => $encryptPhoneId,
                ];
                \Biz\model\brandAccount\BrandAccountAuth::update($data, ['id' => $row['id'], 'phone' => $row['phone']]);
            }
        }
    } else if ($type == 2) {
        //给原始手机号打码
        $list = \Biz\model\brandAccount\BrandAccountAuth::select('*', ['phone_encrypt_id[>]' => 0]);
        foreach ($list as $row) {
            if ($row['phone']) {
                $getPhone = PhoneModel::getExtendPhone($row['phone_encrypt_id'], UserExtendPhoneScene::BRAND_AUTH_INFO_PHONE);
                if ($row['phone'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $row['phone_encrypt_id'], 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'phone' => PhoneCrypto::mask($row['phone'])
                ];
                \Biz\model\brandAccount\BrandAccountAuth::update($data, ['id' => $row['id'], 'phone' => $row['phone']]);
            }
        }
    }
}


function encryptBrandShopInfoPhone($type = 1)
{
    //type,1:给原始手机号加密，并记录加密id 2：给原始手机号打码
    if ($type == 1) {
        //给原始手机号加密，并记录加密id
        $list = \Biz\model\brand\ShopAddres::select('*', ['phone_encrypt_id' => 0]);
        foreach ($list as $row) {
            if ($row['phone']) {
                $encryptPhoneId = PhoneModel::addExtendPhone($row['phone'], UserExtendPhoneScene::BRAND_SHOP_INFO_PHONE);
                if (!$encryptPhoneId) {
                    var_dump('加密失败', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $encryptPhoneId]);
                    continue;
                }
                $getPhone = PhoneModel::getExtendPhone($encryptPhoneId, UserExtendPhoneScene::BRAND_SHOP_INFO_PHONE);
                if ($row['phone'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $encryptPhoneId, 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'phone_encrypt_id' => $encryptPhoneId,
                ];
                \Biz\model\brand\ShopAddres::update($data, ['id' => $row['id'], 'phone' => $row['phone']]);
            }
        }
    } else if ($type == 2) {
        //给原始手机号打码
        $list = \Biz\model\brand\ShopAddres::select('*', ['phone_encrypt_id[>]' => 0]);
        foreach ($list as $row) {
            if ($row['phone']) {
                $getPhone = PhoneModel::getExtendPhone($row['phone_encrypt_id'], UserExtendPhoneScene::BRAND_SHOP_INFO_PHONE);
                if ($row['phone'] != $getPhone) {
                    var_dump('加密和机密手机号不一致', ['id' => $row['id'], 'phone' => $row['phone'], 'phone_encrypt_id' => $row['phone_encrypt_id'], 'get_phone' => $getPhone]);
                    continue;
                }
                $data = [
                    'phone' => PhoneCrypto::mask($row['phone'])
                ];
                \Biz\model\brand\ShopAddres::update($data, ['id' => $row['id'], 'phone' => $row['phone']]);
            }
        }
    }
}


addActivity();
function addActivity()
{
    ActivityBasic::addActivity(ActivityBasic::ACTIVITY_CREATE_WIKI_LIST, '2022年双11清单活动-兴趣公寓');
    ActivityBasic::addActivity(ActivityBasic::ACTIVITY_SPOTLIGHT, '新品聚光灯');
    ActivityBasic::addActivity(ActivityBasic::ACTIVITY_DONGPENG_COLLECT, '东鹏留咨活动页', '2023-03-08');
}

die;
exportDongPengData();
die;
function exportDongPengData()
{
    $fileName = '东鹏留资活动 - ' . date('YmdHis') . ' . csv';
    $filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;
    $fp = fopen($filePath, 'w');
    fputcsv($fp, ['uid', '昵称', '姓名', '电话', '留资时间']);
    $list = ActivityAwardDelivery::select(' * ', ['activity_id' => ActivityAwardDelivery::ACTIVITY_DONGPENG_COLLECT, 'id[>]' => 35]);
    $uids = array_column($list, 'uid');
    $uids = array_filter(array_unique($uids));
    $userList = $uids ? User::getBatchBasicUserInfo($uids) : [];
    $userList = $userList ? array_column($userList, null, 'uid') : [];
    foreach ($list as $row) {
        $phone = PhoneModel::getExtendPhone($row['encrypt_phone_id'], UserExtendPhoneScene::DONGPENG_ACTIVITY_SUBMIT_PHONE);
        $item = [
            $row['uid'] ?: '',
            ($row['uid'] && $userList[$row['uid']]) ? $userList[$row['uid']]['nick'] : '',
            $row['name'],
            $phone,
            $row['created_at']
        ];
        fputcsv($fp, $item);
    }
    fclose($fp);
    \Biz\tools\Mail::send(['tangyiwan@haohaozhu . com'], '东鹏留资活动数据', '东鹏留资活动数据', $filePath);
}


$phone = PhoneModel::getExtendPhone(1, UserExtendPhoneScene::DONGPENG_ACTIVITY_SUBMIT_PHONE);
var_dump($phone);
die;

pushMsg(13657147, '床', 20, Ranking::getRankingUrl(2));
die;


resetWikiRankingList();
die;

/**
 * 重新生成榜单缓存
 * 删除榜单缓存-推荐线、好物推荐线推荐榜单
 * @return void
 */
function resetWikiRankingList()
{
    $rankingIds = Ranking::getHotRankingIds();
    foreach ($rankingIds as $rankingId) {
        cacheWikiRanking::delWikiRankingList($rankingId);
    }
    $list = Biz\service\wikiRanking\Ranking::getListByRankingIds($rankingIds);
    var_dump($list);
}

$link = Ranking::getRankingUrl(2, 1);
pushMsg(13754453, '床', 20, $link);
die;
function pushMsg($uid, $rankingName, $count, $link)
{
    if ($uid) {
        $title = '本周【' . $rankingName . '】榜单已更新';
        $desc = '快来看看住友正在热议的' . $rankingName . ' TOP ' . $count . ' 吧！';
        $pushId = \Doraemon\pockets\constInterface\Push\PushId::BRAND_RANK_WIKI_ACTION . 'ranking_hot_user_' . date('Y - m - d');
        $params = [
            'uid' => $uid,
            'title' => $title,
            'alert' => $desc,
            'param' => [
                'link' => $link,
                'push_id' => $pushId,
                'image' => ''
            ]
        ];
        \Doraemon\service\Push\PushService::send($params);

        $data = [
            'msgCode' => 0,
            'to_uid' => $uid,
            'msgParams' => [
                'title' => $title,
                'detail' => $desc,
                'img' => 'https://img.haohaozhu.cn/Op-imageShow/96b1230ku0af0lz00rqs9cb?iv=1',
                'link' => $link,
                'type' => 2,
            ]
        ];
//        \Doraemon\service\Sysmsg::addMsg(0, $uid, $data['msgParams']);
        \Doraemon\cache\Queue::insertQueue('queue/Sysmsg/Send', $data, \Doraemon\cache\Queue::QUEUE_DORAEMON);
    }
}

$res = getBrandUserInfos([3346, 2833, 2705, 364], true, true);
var_dump(json_encode($res));
die;

function getBrandUserInfos($brandIds, $hasCounter = false, $hasBrandResumeInfo = false)
{
    $list = [];
    $brandList = $brandIds ? BrandService::getBrandInfosCache($brandIds) : [];
    if ($brandList) {
        $uids = array_column($brandList, 'uid');
        $userInfos = User::getBatchBasicUserInfo($uids);
        $userInfos = array_column($userInfos, null, 'uid');
        $extendInfos = MemberExtendInfo::getInfos($uids);
        if ($hasCounter) {
            $userCounterList = UserCounter::getMultiByUids($uids);
        }
        if ($hasBrandResumeInfo) {
            $resumeInfos = BrandResumeInfo::getResumeInfo($brandIds);
            $resumeInfos = $resumeInfos[0];
        }
        foreach ($brandList as $brandId => $row) {
            $uid = $row['uid'];
            $userInfo = $userInfos[$uid] ?? [];
            $extendInfo = $extendInfos[$uid] ?? [];
            $coverImg = empty($extendInfo['cover_img']) ? User::getUserDefaultImg($uid) :
                ImgUrl::getUrl(ImgUrl::APPTYPE_APP, $extendInfo['cover_img'],
                    ImgUrl::IMAGE_SIZE_ORI_NPHONE);
            $defaultLogo = $userInfo ? $userInfo['avatar'] : BrandService::BRAND_DEFAULT_LOGO;
            $logo = $row["logo"] ? ImgUrl::getUrl(ImgUrl::APPTYPE_BIZ, $row["logo"],
                ImgUrl::IMAGE_SIZE_SQ_PHONE) : $defaultLogo;
            $item = [
                'user_info' => [
                    'uid' => (int)$userInfo['uid'],
                    'nick' => $userInfo['nick'],
                    'type' => (int)$userInfo['type'],
                    'avatar' => $userInfo['avatar'],
                    'small_avatar' => $userInfo['avatar'],
                    'big_avatar' => $userInfo['avatar'],
                    'cover_img' => $coverImg,
                    'brand' => [
                        'brand_id' => $brandId,
                        'uid' => $uid,
                        'logo' => $logo,
                        'name' => $row['brand_name']
                    ]
                ]
            ];
            if ($hasCounter) {
                $item['counter'] = $userCounterList[$uid] ?? [];
            }
            if ($hasBrandResumeInfo) {
                $item['resume_info'] = $resumeInfos[$brandId] ?? [];
            }
            $list[] = $item;
        }
    }
    return $list;
}

/**
 * 榜单数据缓存
 * @return void
 */
function setWikiRankingDataIds($day)
{
    $where = [
        'ranking_day' => $day,
        'ORDER' => ['rank_cnt' => 'DESC'],
    ];
    $rankingDatalist = WikiRankingData::selectByWhere($where);
    foreach ($rankingDatalist as $row) {
        var_dump($day, $row['ranking_id'], $row['rank_cnt']);
        \Biz\cache\wiki\WikiRanking::setWikiRankingDataIds($day, $row['ranking_id'], $row['rank_cnt']);
    }
    var_dump(\Biz\cache\wiki\WikiRanking::getWikiRankingDataIds($day));
}


$dir = '/Users/yiwan/Desktop/品牌权益icon/';
$result = uploadImgs($dir);
var_dump(json_encode($result));
die;
/**
 * 上传文件夹下图片
 * @param $dir
 * @return array
 */
function uploadImgs($dir)
{
    $result = [];
    $file_list = [];
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file == '..' || $file == '.') continue;
            if (is_file($dir . '/' . $file)) {
                $file_list[] = ['path' => $dir . '/' . $file, 'name' => $file];
            }
        }
        closedir($handle);
    }
    foreach ($file_list as $row) {
        $file = $row['path'];
        try {
            $uploadResult = \Hhzbeads\Img\ImgUpload::upload(\Doraemon\tools\ImgUrl::APPTYPE_OP, $file);
        } catch (\Exception $e) {
            var_dump($e->getMessage(), $file);
            continue;
        }
        $picId = '';
        $url = '';
        if (is_array($uploadResult) && !empty($uploadResult)) {
            $picId = $uploadResult['ori_pic_id'];
            $url = toolImgUrl::getUrl(toolImgUrl::APPTYPE_OP, $picId, toolImgUrl::IMAGE_SIZE_OP_ORI);
        }
        $result[] = [
            'name' => $row['name'],
            'pic_id' => $picId,
            'url' => $url
        ];
    }
    return $result;
}

die;


$params = [
    'update_time_start' => strtotime('-1 hours'),
    'update_time_end' => time()
];
$res = \Doraemon\tools\Youzan::refundSearch(1, 100, $params);
var_dump($res);
die;

//testChangeDeliver();
die;
//testDeliver();
die;

function testDeliver()
{
    var_dump('测试发货');
    $tid = 'E20221117131243072706161';
    $expressId = 3;//中通快递
    $expressNo = '75550449103180';
    $oid = '2907474125679100009';
    $res = \Doraemon\tools\Youzan::OrderDeliver($tid, $expressId, $expressNo, [$oid]);
    var_dump($res);
}

function testChangeDeliver()
{
    var_dump('测试更改物流');
    $tid = 'E20221117131243072706161';
    $distId = '202211171316270000060727';
    $expressNo = '75550375369306';
    $expressId = 3;//中通快递
    list($msec, $sec) = explode(' ', microtime());
    $mesctime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
    $modify = [
        [
            'dist_id' => $distId,
            'express_no' => $expressNo,
            'express_id' => (int)$expressId,
            'version' => $mesctime
        ]
    ];
    $res = \Doraemon\tools\Youzan::OrderDeliverUpdate($tid, $modify);
    var_dump($res);
}


//var_dump(json_encode(\Biz\service\SuperSubsidy\YouZanOrder::getExportOrderData($tid)));
die;


fixEmptyTags();
die;

function fixEmptyTags()
{
    $album_ids = AlbumListModel::select('album_id', ['tags' => '']);
    foreach ($album_ids as $album_id) {
        $tagNameArr = AlbumRelateTagsModel::selectByWhere(['album_id' => $album_id, 'status' => AlbumRelateTagsModel::STATUS_NORMAL], 'tag_name');
        if ($tagNameArr) {
            $tags = $tagNameArr ? implode(',', $tagNameArr) : '';
            AlbumListModel::update(['tags' => $tags], ['album_id' => $album_id]);
            var_dump(AlbumListModel::log());
        }
    }
}


$list = \Biz\service\Album\AlbumListService::getAlbumListByAlbumIds(['00000bb1200bonyc', '00000bc1200bonyc', '00000ba1200bonyc']);
var_dump(json_encode($list));
die;

$content = '【淘宝】
https://m.tb.cn/h.Uf6gQ0L?tk=GG4Ad01iA3L
CZ3457「儿童雪花片加厚大号积木拼装玩具女孩男
孩幼儿园宝宝益智力拼插片」
点击链接直接打开或者淘宝搜索直接打开';

$info = \Biz\scraper\GoodsInfo::getGoodsInfo($content);
var_dump($info);
die;

$result = squareRecommend();
var_dump(json_encode($result));
die;

$url = 'https://www.samsungeshop.com.cn/product/QA55LS01CAJXXZ?cid=cn_paid_display_marketing_ctv-ls01c_estore_qa55ls01cajxxz_other_hhz-220921_none';
$info = \Biz\module\Classes\wiki\Wiki::getWikiByContent($url);
var_dump($info);
die;

$avatarArr = \Biz\module\Classes\wiki\Wiki::getRandUserCoverImg(300);
$avatarArr = array_column($avatarArr, 'cover_img');
$res = [];
for ($i = 0; $i < 200; $i++) {
    $randIndex = rand(0, count($avatarArr));
    $avatar = $avatarArr[$randIndex] ?? '';
    unset($avatarArr[$randIndex]);
    $res[] = $avatar;
}
$res = array_filter($res);
var_dump(count($res));
$res = array_unique($res);
var_dump(count($res));
die;

$blankIds = [];
$page = 1;
$delBlankIds = [];
do {
    $blankIds = \Biz\model\wiki\ObjRelateWiki::select('obj_id', ['obj_type' => 2, 'status' => 1, 'LIMIT' => [($page - 1) * 500, 500]]);
    if ($blankIds) {
        $delbids = \Doraemon\model\Blank::select("bid", [
            'AND' => [
                'bid' => $blankIds,
                'status' => 9
            ]
        ]);
        var_dump('page:' . $page . '#count:' . count($delbids));
        $delBlankIds = array_merge($delBlankIds, $delbids);
    }
    $page++;
} while ($blankIds);
$delBlankIds = array_unique($delBlankIds);
var_dump(json_encode(['del_bids' => $delBlankIds]), count($delBlankIds));
foreach ($delBlankIds as $blankId) {
    $uid = IdParse::getUid($blankId);
    if ($uid) {
        var_dump('解除wiki关联，uid:' . $uid . '#bid:' . $blankId);
        \Biz\service\wiki\ObjRelateWiki::delBlankRelate($uid, $blankId);
    }
}
die;


$objId = '0004txk050001zun';
$obj_info[0]['obj_id'] = $objId;
$obj_info[0]['obj_type'] = IdParse::getType($objId);
$objId = '0004twe05000fgj1';
$obj_info[1]['obj_id'] = $objId;
$obj_info[1]['obj_type'] = IdParse::getType($objId);
$obj_infos = \Doraemon\service\Format\FormatMix::format($obj_info, 1582647, \Doraemon\pockets\constInterface\FormatScene::TALK_ABOUT_INFO) ?: [];
var_dump($obj_infos);
die;
$res = HandleBlank::handleBlank(['0004txk050001zun'], HandleBlank::FEED, 1582647);
var_dump($res);
die;

changeFlowRate(6, 0.5);
die;
/**
 * 更改cpm计划的真实流量比例
 * @param $planId 计划id
 * @param $rate 流量比例
 * @return void
 */
function changeFlowRate($planId, $rate)
{
    $info = \Biz\model\bizAd\AdPlan::getPlanInfo($planId);
    if ($info) {
        $flowPackageIds = \Biz\model\bizAd\AdPlanDataFlow::select('flow_package_id', ['plan_id' => $planId]);
        var_dump($info, $flowPackageIds);
        $realTargetCount = bcmul($info['target_count'], $rate);
        $data = [
            'flow_rate' => $rate,
            'real_target_count' => $realTargetCount,
            'expose_count' => bcdiv($info['real_expose_count'], $rate)
        ];
        var_dump($data);
        die;
        \Biz\model\bizAd\AdPlan::update($data, ['id' => $planId]);
        if ($flowPackageIds) {
            \Doraemon\model\Flow\FlowPackage::update(['target_exposure' => $realTargetCount], ['id' => $flowPackageIds]);
        }
        die;
    }
}

$remarkArr = [
    '三星电视', 'Neo QLED', 'Lifestyle', 'The Frame画壁', 'The Frame', '画壁', 'The Serif画境', 'The Serif', '画境'
];
$fileName = 'note-' . date('YmdHis') . '.csv';
$filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;
var_dump($filePath);
$fp = fopen($filePath, 'w');
fputcsv($fp, ['关键词', '链接', 'uid', '昵称', '身份', '发布时间', '点赞数', '收藏数', '评论数']);
foreach ($remarkArr as $remark) {
    $where['text_remark'] = $remark;
    $where['addtime[>=]'] = strtotime('2015-01-01');
    $where['addtime[<=]'] = date('Y-m-d H:i:s');
    $where['LIMIT'] = [0, 500];
    $result = Photo::getNoteListByParams($where, 'id');
    $photoIds = array_column($result['rows'], 'id');
    $photoInfos = sPhotos::getPhotos($photoIds);
    $uids = array_column($photoInfos, 'uid');
    $userInfos = Member::getUserInfoByIds($uids);
    $userList = array_column($userInfos, null, 'uid');
    $count = PhotoCounter::getMulti($photoIds);
    var_dump($remark . ' note 数量:' . count($photoInfos));
    foreach ($photoInfos as $row) {
        $item = [
            $remark,
            'https://m.haohaozhu.cn/tupian/' . $row['id'] . '.html',
            $row['uid'],
            $userList[$row['uid']]['nick'],
            Member::$typeDesc[$userList[$row['uid']]['type']],
            date('Y-m-d H:i:s', $row['addtime']),
            $count[$row['id']]['like'],
            $count[$row['id']]['favorite'],
            $count[$row['id']]['comments'],
        ];
        fputcsv($fp, $item);
    }
}
fclose($fp);

die;


$arr = [
    [
        'id' => 11, 'name' => 'a11', 'imgs' => ['a21.jpg', 'a11.jpg'],
    ],
    [
        'id' => 22, 'name' => 'a22', 'imgs' => ['b22.jpg', 'b11.jpg'],
    ],
    [
        'id' => 138, 'name' => 'a138', 'imgs' => ['c33.jpg', 'c138.jpg'],
    ]
];
$i_arr = [
    [
        'id' => 77, 'name' => 'a11', 'imgs' => ['a231.jpg', 'a131.jpg'],
    ],
    [
        'id' => 33, 'name' => 'a22', 'imgs' => ['b222.jpg', 'b111.jpg'],
    ]
];
array_splice($arr, 2, 0, $i_arr);
$i_arr = [['id' => 3113, 'name' => 'a23332', 'imgs' => ['b2232.jpg', 'b1171.jpg']]];
array_splice($arr, 3, 0, $i_arr);
var_dump(json_encode($arr));
die;

$info = \Doraemon\tools\Youzan::getItemDeatil(2068810018);
var_dump(json_encode($info));
$info = \Doraemon\tools\Youzan::getSecKillInfo(4330761155);
var_dump(json_encode($info));
die;

var_dump(\Doraemon\tools\Youzan::getGoodsList(1, 20));
die;

var_dump(TbkUnion::tbkCouponConvert('brZdoPKIBo4V9DjnIWO', TbkUnion::ADZONE_ID, '', 3));
die;
$content = '99￥6Ib02vVqp1r￥ https://m.tb.cn/h.UZvlykk  CZ3457 北欧NORHOR/进口/英国Reeves原版/MARM大理石金属茶几黑白2色T/K';
$info = TbkUnion::tbkCouponConvert($content);
var_dump($info);
$info = TbkUnion::getItemInfo($info['num_iid'], $info['biz_scene_id']);
var_dump($info);
die;

$url = "https://uland.taobao.com/item/edetail?id=BOpVvk8H6toqPKDuMATdCe-VgROq4QCkWQXJm9zigp";
var_dump(TbkUnion::tbkDgOpMaterialOptional($url));
die;

$client = new Client([
    RequestOptions::TIMEOUT => 10
]);
$response = $client->get($url);
$content = $response->getBody()->getContents();
var_dump($content);
die;

$url = "https://detail.m.tmall.com/item.htm?id=678739506003";
var_dump(TbkUnion::getItemInfo('VgROq4QCkWQXJm9zigp', TbkUnion::BIZ_SCENE_ID3));
die;

$content = '【淘宝】https://m.tb.cn/h.U1Hv38w?tk=BFZD2Eh2yZ9 CZ3457 「三角地缝刷卫生间地板刷无死角浴室墙角凹槽缝隙厕所硬毛清洁刷子」
点击链接直接打开';
$info = TbkUnion::tpwdConvert($content);

$info = TbkUnion::getItemInfo(678739506003, TbkUnion::BIZ_SCENE_ID1);
var_dump($info);
die;
var_dump(\Doraemon\tools\Youzan::test());
die;

//var_dump(TbkUnion::tbkDgOpMaterialOptional('https://item.taobao.com/item.htm?id=679575372155'));
//die;
$itemIds = [675510043208, 675684661133, 679575372155];
$newItemIds = ['dkZ2aq6Cn7w0Y29ZSn', 'MJ0rx95UVbbrdxAziZW', 'o2Z5GyxUBDzMwdoah4'];
$itemId = 679575372155;
$newItemId = 'o2Z5GyxUBDzMwdoah4';
$content = '【淘宝】https://m.tb.cn/h.U1Hv38w?tk=BFZD2Eh2yZ9 CZ3457 「三角地缝刷卫生间地板刷无死角浴室墙角凹槽缝隙厕所硬毛清洁刷子」
点击链接直接打开';
$info = TbkUnion::tpwdConvert($content);
var_dump($info);
die;
$info = TbkUnion::getItemInfo($newItemId, TbkUnion::BIZ_SCENE_ID3);
var_dump($info);
var_dump($info, TbkUnion::tbkCouponConvert($info));
die;
var_dump(TbkUnion::tbkDgOpMaterialOptional($info['item_url']));
die;
$clickUrl = TbkUnion::tbkCouponConvert($newItemId, TbkUnion::ADZONE_ID, '', 3);
var_dump($clickUrl);
die;
var_dump(TbkUnion::tbkTpwdCreate($clickUrl));
die;

//$res=TbkUnion::tbkCouponConvert('brZdoPKIBo4V9DjnIWO',TbkUnion::ADZONE_ID,"",2);
//var_dump($res);die;

$content = '【淘宝】https://m.tb.cn/h.UbpwxCh?tk=bLuS2EdLaWJ CZ3457 「无线蓝牙键盘迷你充电静音适用于苹果手机iPhone平板iPad安卓电脑」
点击链接直接打开';
$content = '【淘宝】https://m.tb.cn/h.UZAJLBG?tk=QY0B2vSE2A1 CZ3457 「ZOOM F2&F2-BT超小型蓝牙32Bit外景手机相机场vlog录音机22dv」点击链接直接打开';
var_dump(TbkUnion::tpwdConvert($content));
die;
var_dump(\Biz\scraper\GoodsInfo::getUrl($content));
die;

var_dump(TbkUnion::tbkCouponConvert('brZdoPKIBo4V9DjnIWO', TbkUnion::ADZONE_ID, '', 3));
die;
$url = 'https://uland.taobao.com/coupon/edetail?e=xnfiIKAuL0ANfLV8niU3R2PGlW5f4%2BxfH%2FquueCqts1a4rBpq3tSHSx%2F%2FCnRy7po%2FdzZYmukDsESwGdedzkKTPbk9HtRh%2FSe%2F9HYhYNjyyALR1ytXXUSFTFRvssVIAAmzAECzTocA7OhmTIXrA6OWU5MnvvGDGnt8Lh0xfyLGVMrSHP8SSQwoIpMu6KsCQhkDNS%2F5hK2vLt%2BOHfs5nLQGA%3D%3D&&app_pvid=59590_33.62.127.187_846_1662260204406&ptl=floorId:31069;app_pvid:59590_33.62.127.187_846_1662260204406;tpp_pvid:&union_lens=lensId%3AOPT%401662260204%40213e7fbb_09be_183066dd39c_7d12%4001';
//$url='https://m.tb.cn/h.UbLg1ZX';
//$content='【淘宝】https://m.tb.cn/h.UZAJLBG?tk=QY0B2vSE2A1 CZ3457 「ZOOM F2&F2-BT超小型蓝牙32Bit外景手机相机场vlog录音机22dv」点击链接直接打开';
//$content='99￥8sy42vVqbk3￥ https://m.tb.cn/h.UbLg1ZX  CZ0001 北欧NORHOR/进口/英国Reeves原版/MARM大理石金属茶几黑白2色T/K';
//$content='99￥6Ib02vVqp1r￥ https://m.tb.cn/h.UZvlykk  CZ3457 北欧NORHOR/进口/英国Reeves原版/MARM大理石金属茶几黑白2色T/K';
var_dump(RealUrl::getRealUrl($url));
var_dump(\Biz\scraper\GoodsInfo::getUrl($url));
die;

$url = "//s.click.taobao.com/t?e=m%3D2%26s%3DodvJC2FBjtccQipKwQzePOeEDrYVVa64r4ll3HtqqoxyINtkUhsv0AaRaxEUTKfah1NN1ZbNtK8WKO5a%2FYmzChjk44Dz1EkOZoUGHEz20Rp%2FzsCHH9mhPHjRAwXv0Qf4Q46khh5diznJRnj1wsSUO%2FEqaJ4fM8g8mQyAYtBXd3lg9V5ruYZuRbAsc%2FuJdmNQxg5p7bh%2BFbQ%3D&scm=null&pvid=1502356a-6fea-40f2-ae20-dc17f40d28a1&app_pvid=59590_33.39.139.150_773_1662445445089&ptl=floorId:2836;originalFloorId:2836;pvid:1502356a-6fea-40f2-ae20-dc17f40d28a1;app_pvid:59590_33.39.139.150_773_1662445445089&xId=4DpzdV11C7An8EqnlcUVAPpoVpDMQnEXwYFoFBmKDgVRYWO5bM6kPHk8ZIRcg3xZJ0In1FhHID7vPj8r9nTwIcju4VgbqVfg9uhQVtqVXBNP&union_lens=lensId%3AMAPI%401662445445%4021278b96_0b8d_18311785ff7_b3a6%4001";
\Biz\cache\wiki\TbkUrl::setUrl(680701683994, $url);
die;
die;

$url = 'https://detail.tmall.hk/hk/item.htm?tbpm=1&id=680858018927&ali_refid=a3_431358_1007:506950145:U:506950145_0_3703875087:99c4fe074bf1675b87fc3e428825daca&ali_trackid=149_99c4fe074bf1675b87fc3e428825daca&spm=a21bo.jianhua.201876.25&scm=1007.40986.275655.0&skuId=4880785369211';
$url = 'https://detail.tmall.com/item.htm?ali_refid=a3_431358_1007:13579762:U:13579762_0_3698567299:491d1cd80811109d00f56ad56f1db472&ali_trackid=149_491d1cd80811109d00f56ad56f1db472&id=680701683994&scm=1007.40986.275655.0&spm=a21bo.jianhua.201876.17&sku_properties=1627207:130164';
var_dump(\Biz\module\Classes\wiki\Wiki::getWikiByContent($url));
var_dump(\Biz\cache\wiki\TbkUrl::ttl('tbk_url680701683994'));
die;

var_dump(\Biz\scraper\GoodsInfo::getGoodsInfo('https://new.m.taobao.com/detail.htm?id=666956001499'));
die;

var_dump(TbkUnion::tpwdConvert('【淘宝】https://m.tb.cn/h.UbteaKA?tk=e75w2vSNEzm CZ3457 「蔚来NIO Life NOMI小米联名Populele2尤克里里智能科技乐器入门琴」
点击链接直接打开'));
die;

//验证淘宝联盟新旧商品ID
testTbkSdkUpgrade();
die;
function testTbkSdkUpgrade()
{
    $list = mWiki::select('*', ['channel' => mWiki::CHANNEL_TAOBAO, 'channel_jump_params[!]' => '', 'LIMIT' => [0, 10], 'ORDER' => ['id' => 'ASC']]);
    foreach ($list as $row) {
        $numItemId = $row['channel_spu_id'];
        $newItemId = $row['channel_jump_params'];
        echo '淘宝主站ID:' . $numItemId . '#淘宝联盟ID:' . $newItemId . PHP_EOL;
        echo '一、数字ID相关：' . PHP_EOL;
        echo '1.1.淘宝主站数字ID链接:' . PHP_EOL;
        echo RealUrl::formatLink($numItemId, 1) . PHP_EOL;;
        $couponInfo = TbkUnion::tbkCouponConvert($numItemId);
        echo '1.2.淘宝联盟转链数字ID链接:' . PHP_EOL;
        echo $couponInfo['item_url'] . PHP_EOL;
        $tpwd = $couponInfo['item_url'] ? TbkUnion::tbkTpwdCreate($couponInfo['item_url']) : '';
        echo '1.3.淘宝联盟数字ID转淘口令：' . PHP_EOL;
        echo $tpwd['model'] . PHP_EOL;
        $opMaterialInfo = TbkUnion::tbkDgOpMaterialOptional(RealUrl::formatLink($numItemId, 1));
        $opMaterialInfo = $opMaterialInfo[0] ?? [];
        echo '1.4.淘宝联盟数字ID物料搜索-商品链接：' . PHP_EOL;
        echo $opMaterialInfo['item_url'] . PHP_EOL;;
        $spreadInfo = TbkUnion::TbkSpreadGet($couponInfo['item_url']);
        $spreadInfo = $spreadInfo[0] ?? [];
        echo '1.5.淘宝联盟数字ID长链转短链:' . PHP_EOL;
        echo $spreadInfo['content'] . PHP_EOL;;

        echo '二、字符串ID相关：' . PHP_EOL;;
        $tbkUnionInfo = TbkUnion::getItemInfo($newItemId, 3);
        echo '2.1.淘宝联盟字符串ID链接:' . PHP_EOL;
        echo $tbkUnionInfo['item_url'] . PHP_EOL;;
        $couponInfo = TbkUnion::tbkCouponConvert($newItemId, TbkUnion::ADZONE_ID, '', 3);
        echo '2.2.淘宝联盟转链字符串ID链接:' . PHP_EOL;
        echo $couponInfo['item_url'] . PHP_EOL;;
        $tpwd = $couponInfo['item_url'] ? TbkUnion::tbkTpwdCreate($couponInfo['item_url']) : '';
        echo '2.3.淘宝联盟字符串ID转淘口令：' . PHP_EOL;
        echo $tpwd['model'] . PHP_EOL;;
        $opMaterialInfo = TbkUnion::tbkDgOpMaterialOptional($tbkUnionInfo['item_url']);
        $opMaterialInfo = $opMaterialInfo[0] ?? [];
        echo '2.4.淘宝联盟字符串ID物料搜索-商品链接：' . PHP_EOL;
        echo $opMaterialInfo['item_url'] . PHP_EOL;;
        $spreadInfo = TbkUnion::TbkSpreadGet($couponInfo['item_url']);
        $spreadInfo = $spreadInfo[0] ?? [];
        echo '2.5.淘宝联盟字符串ID长链转短链:' . PHP_EOL;
        echo $spreadInfo['content'] . PHP_EOL;;
        echo '#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-' . PHP_EOL;
    }
}

die;
$itemId = '5PmNYzVU68JwYuNy';
$res = TbkUnion::getItemsInfo($itemId, 3);
var_dump($res);
die;

$itemId = 'PWZeO2c3tBP454UVMCPt6-5PmNYzVU68JwYuNy';
$res = TbkUnion::tbkCouponConvert($itemId);
var_dump($res);
die;

$itemId = '5PmNYzVU68JwYuNy';
$res = TbkUnion::tbkItemInfo($itemId, 2, 3);
var_dump($res);
die;

$res = TbkUnion::tbkItemInfo(669173796227);
var_dump($res);
$itemId = 'B0WxGezUgw64WYn0CD0';
$res = TbkUnion::tbkItemInfo($itemId, 2, 3);
var_dump($res);
die;
var_dump(\Biz\tools\OneBound::getTaoBaoItemInfo(675488330488));
die;

$res = TbkUnion::tbkItemInfo('602296853480,182493960, 325559743, 569624415,1039185589,1396403957,1795481479,37517399132,37530146697,37535188826,37593512712', 2, 1);
var_dump(json_encode($res));
die;
$itemId = 'x0dDOu9YZ6BTJMMTRANPQUpG-BVg3wKirrXaKwrjU0';
$itemId = '659137179291';
$res = TbkUnion::tbkItemIdtransForm([602296853480, 182493960, 325559743, 569624415, 1039185589, 1396403957, 1795481479, 37517399132, 37530146697, 37535188826, 37593512712]);
var_dump($res);
die;
//var_dump($res);
//die;
$itemId = 'brZdoPKIGGMqJVGKFZ';
$itemId = '659137179291';

var_dump(TbkUnion::tbkItemInfo($itemId, 2, 2));
die;

$url = TbkUnion::tbkCouponConvert($itemId, TbkUnion::ADZONE_ID4);

var_dump($url);
var_dump(TbkUnion::tbkTpwdCreate($url['item_url']));
die;

$res = TbkUnion::tbkItemIdtransForm([658649457571, 659137179291, 659486806069]);
var_dump($res);
die;

$url = \Biz\tools\TbkUnion::getTbkUrl(611633818391);
var_dump($url, \Biz\cache\wiki\TbkUrl::ttl('tbk_url611633818391'));
die;


$url = \Biz\tools\JdUnion::tryGetItemUnionUrl(10034721973254);
var_dump($url, JdUnionUrl::ttl('jd_union_url10034721973254'));
die;

var_dump(\Biz\module\Classes\wiki\Infos::infos([144389, 137624], \Biz\module\Classes\wiki\Infos::FIELDS_GROUP_SIMPLE_LIST));
die;

$day = 20210130;
$duration_uids = LiveUserKeepTimeTop3::select('uid', ['day' => $day, 'room_id' => 578, 'LIMIT' => [0, 3], 'ORDER' => ['user_keep_time' => 'DESC', 'uid' => 'DESC']]);
var_dump(LiveUserKeepTimeTop3::log());
$duration_uids = $duration_uids ? $duration_uids : [];
var_dump($duration_uids);
die;

var_dump(\Biz\model\bigData\RankingHotUser::getUserRanking());
$where['uid'] = [1582647];
$where['day'] = date('Ymd', strtotime('-1 day'));
$data = UserConsumeDecisionScore::select('*', $where);
var_dump($data);
die;

$wikiList = \Biz\model\Album\AlbumWikiListModel::selectByWhere([
    'album_id' => '00000157771200boooe',
    'status' => \Biz\model\Album\AlbumWikiListModel::STATUS_NORMAL,
    'ORDER' => ['sort' => 'ASC', 'addtime' => 'DESC']
]);
var_dump(\Biz\model\Album\AlbumWikiListModel::log());
die;

$res = TbkUnion::tbkDgOpMaterialOptional('https://detail.tmall.com/item.htm?id=610957392110');
var_dump($res);
die;

var_dump(bcdiv(4000, 0.8));
var_dump(floor(bcmul(0.8, 4000, 2)));
die;

//修复历史数据
$list = \Biz\model\bizAd\AdPlan::select('*', ['real_target_count' => 0, 'real_expose_count' => 0]);
foreach ($list as $row) {
    \Biz\model\bizAd\AdPlan::update([
        'real_target_count' => bcmul($row['flow_rate'], $row['target_count']),
        'real_expose_count' => bcmul($row['flow_rate'], $row['expose_count']),
    ], ['id' => $row['id']]);
}
die;


$rate = \Biz\model\bizAd\AdPlanFlowRate::getUserFlowRate(0);
var_dump($rate);
$rate = \Biz\model\bizAd\AdPlanFlowRate::getUserFlowRate(1582647);
var_dump($rate);
$rate = \Biz\model\bizAd\AdPlanFlowRate::getUserFlowRate(11904);
var_dump($rate);
die;

//首页弹屏截止到7月27日，近3个月弹屏图片id
$imgIds = [
    "0950130ku0pp0i000rch7c2", "3e8f530ku0pp0NE00rc657v", "d00f330ku0pp0iM00rciwz0", "6ba0b30ku0pp0Uy00rcja2p", "bc3dc30ku0pp0ZG00rcja7l", "d342a30ku0pp0B100rcje1x", "daa1430ku0pp0Xg00rcmfp4", "8fb9c30ku0pp05500rcmpdk", "93c2530ku0pp0bl00rcogiy", "d342a30ku0pp0B100rcje1x", "ac79f30ku0pp0cl00rcpcu4", "402d930ku0pp0Xm00rcqo9o", "29ad030ku0pp0bR00rcqpcq", "8ae6530ku0pp0F900rcqpvi", "732cb30ku0pp0Db00rcr6zx", "4f82a30ku0pp0t000rcr90f", "a8fa830ku0pp0P800rcscdz", "9c05530ku0pp0qe00rctwk4", "bc74930ku0pp0G700rctwlp", "679ff30ku0pp01x00rctwmt", "25a9030ku0pp0zt00rctwop", "00a1a30ku0pp0Qn00rcu9me", "d83b330ku0pp0NB00rcuahw", "10cd030ku0pp0Xb00rcuds0", "470bc30ku0pp0ug00rd1tbv", "e03b030ku0pp01L00rd3g3l", "c5f1530ku0pp00q00rd3ofo", "b0bc530kv0pq04S00rd45rg", "0f01630ku0pp0hq00rd53uw", "940a730ku0pp0Wb00rd53vj", "8d77520ku0pp0sJ00rd5l8p", "23a1830ku0pp0wT00rd6yan", "0329430ku0pp0Lr00rd8urd", "6e38320ku0pp0yr00rd77g1", "2bb0c30ku0pp01N00rdc9rq", "bd0c530ku0pp0bO00rd9bsk", "6180530ku0pp0e000rd9c1v", "33e2020ku0pp0Xg00rdem74", "3d44430ku0pp06b00rddeft", "5253c30ku0pp0O400rdexag", "f4e3930ku0pp0Jg00rdexga", "c116830ku0pp0UV00rdfykk", "cf66f30ku0pp0Ag00rdi0or", "734d930ku0pp0s000rdk2aw", "6fd5130ku0pp0h200rdoh65", "0a2fc30ku0pp0Xh00rdrm9c", "3de2130ku0pp0Id00rdqew2", "109bc30ku0pp0kq00rdrnee", "d370a30ku0pp0Kf00rdrxaq", "1a0a530ku0pp0zD00rdrxcv", "e083330ku0pp0tQ00rdrxo3", "8921630ku0pp06q00rdtp4l", "0d98c30ku0pp0fM00rdvi4d", "9dde930ku0pp0RS00rdx3jo", "0b84930ku0pp0z700rdz3lr", "3636130ku0pp0Tk00rdz3nd", "a2d1730ku0pp07700re1hd8", "efb2630ku0pp0Cv00re4if4", "1661e30ku0pp0Hg00re4jf3", "fe1b730ku0pp0hb00re4k2m", "3c32d30ku0pp0v300re4k9a", "182a630ku0pp0Y100re4kaq", "8b5e530ku0pp0Dk00re4kbx", "e57fb30ku0pp0hj00re4kdz", "84f5e30ku0pp0ca00re4kpq", "b36eb30ku0pp0P400re4krc", "5222430ku0pp0pf00re4ksm", "face430ku0pp0WN00re4kts", "30d1430ku0pp0IJ00re4kv7", "fe30c30ku0pp0VG00re4vkd", "f66c230ku0pp0iA00re7wns", "e079830ku0pp03q00re8lhf", "1f70630ku0pp0HB00re8m9a", "f5a2030ku0pp0RQ00re9qxv", "004fc30ku0pp0SZ00re9r0v", "f069e30ku0pp0Xd00rea8cs", "da38a30ku0pp0l400rea968", "f31c430ku0pp0Tx00reblyr", "c20c330ku0pp0aM00reeamc", "af43f30ku0pp0mJ00rejjwb", "46d2830ku0pp0ja00rejzju", "4984a30ku0pp0nG00rekvy0", "739e730ku0pp0T500rellwk", "97d1430ku0pp04U00ren9jl", "7062f30ku0pp0iG00renb88", "d5d3930ku0pp0q700renqti", "9e4ec30ku0pp0uS00rercxg", "66d7130ku0pp0p400reut44", "9c74e30ku0pp0Ar00reut71", "66d7130ku0pp0p400reut44", "9c74e30ku0pp0Ar00reut71", "2265730ku0pp0cZ00rexu0x", "4bec830ku0pp0LQ00reyiuq", "1d1d430ku0pp0AX00rf0cz2", "73a6230ku0pp0yh00rf0d51", "4f85030ku0pp0Yy00rf27of", "899ab20ku0pp01f00rf27qx", "c06c730ku0pp0va00rf4atr", "6962c30ku0pp0qW00rf4b02", "fa6e330ku0pp0rh00rf4b2q", "650c230ku0pp07i00rf7szm", "439da30ku0pp0wd00rf95ab", "5118630ku0pp0BC00rfbixi", "ceddd30ku0pp06H00rfdam8", "89e7630ku0pp0Nh00rff648", "1156030ku0pp0l300rff6fq", "d7cec30ku0pp01f00rff6r8", "88e7c30ku0pp08i00rfh875", "1f82130ku0pp0OC00rfkl3s", "66ead30ku0pp0X600rfklf1"
];

//ifttt截止到7月27日，近3个月弹屏图片id
$imgIds = [
    "034f430ku0pp0an00rbcxsx", "ff3e430b40b40MK00rbneo2", "baaeb30b40b40Xb00rbfxsq", "4ce5430b40b40et00rbnesc", "3a6f830b40b40gP00rbneth", "bdfab30b40b40lx00rbelm5", "2611e30ku0pp05Y00rbiciv", "0239f30ku0pp0Lo00rbt57r", "c68d130ku0pp0o600rbt5lz", "bf9bf20ku0pp0wF00rbtqpf", "bda0a30ku0pp0Bz00rc47lw", "83fc530ku0pp0Q800rc69cn", "2b39a30ku0pp0dn00rcj846", "60e8330ku0pp0gS00rcqfb4", "265a730ku0pp05D00rcqhv7", "b063330ku0pp0co00re69ks", "b36b020dm0cu02b00re87mx", "8256930dm0cu0LZ00re89fp", "5f86630dm0cu0Ij00re8a2h", "846b730dm0cu0kF00rej9vp", "633ca30dm0cu0H100rejcd1", "7365930ku0pp0QO00rempjx", "4964430ku0pp0IK00rew6r0", "b169e30ku0pp0eP00rfb499", "f433230ku0pp0Zc00rf8xrl", "3359d30ku0pp0pL00rfei8i",
];

$arr1 = [];//500k及以下
$arr2 = [];//500k-1M
$arr3 = [];//1M及以上
foreach ($imgIds as $id) {
    $url = ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $id, ImgUrl::IMAGE_SIZE_OP_ORI);
    $size = getFileSize($url);
    if ($size <= 500) {
        $arr1[$id] = $size;
    } else if ($size > 500 && $size < 1024) {
        $arr2[$id] = $size;
    } else if ($size >= 1024) {
        $arr3[$id] = $size;
    }
}
var_dump(count($imgIds), count($arr1), count($arr2), count($arr3), $arr3);
die;
function getFileSize($url)
{
    $res = get_headers($url, true);
    $filesize = round($res['Content-Length'] / 1024, 2);
    return $filesize;
}

$res = \Biz\model\wiki\MGoodsAlbum::apiAllList(1, 1, 20);
var_dump(json_encode($res));
die;

//$res=\Biz\tools\JdUnion::getOrder('2022-07-22 10:00:00','2022-07-22 11:00:00',1,1,2);
//var_dump(json_encode($res));die;

//$res=\Biz\tools\JdUnion::getItemInfo(10034785754265);
//var_dump($res);die;
//$res=\Biz\tools\JdUnion::getBigItemInfo([10034785754265],['categoryInfo', 'imageInfo', 'detailImages']);
//var_dump($res);die;
$res = \Biz\tools\JdUnion::tryGetItemUnionUrl(10034785754265);
var_dump($res);
die;

$app = \Biz\tools\JdUnion::getApp();
//$result=$app->good->jingfen(['eliteId'=>1]);
//var_dump($result);die;
$result = $app->link->get('https://item.jd.com/10034785754265.html');
var_dump($result);
die;


//获取obj_id todo 验证
$uid = 1582647;
$albumId = getAlbumId($uid);
var_dump('album_id:' . $albumId . '#type:' . getObjType($albumId));
$photoId = getPhotoId($uid);
var_dump('photo_id:' . $photoId . '#type:' . getObjType($photoId));
$articleId = getArticle($uid);
var_dump('article_id:' . $articleId . '#type:' . getObjType($articleId));
$diaryBookId = getDiaryBookId($uid);
var_dump('diary_book_id:' . $diaryBookId . '#type:' . getObjType($diaryBookId));
die;

function getAlbumId($uid)
{
    $objType = '12';
    $maxCounterId = getMaxCounterId('goods_album');
    $uid36Str = uidToStr36($uid);
    return $maxCounterId . $objType . $uid36Str;
}

function getPhotoId($uid)
{
    $objType = '0';
    $maxCounterId = getMaxCounterId('photosid');
    $uid36Str = uidToStr36($uid);
    return $maxCounterId . '0' . $objType . $uid36Str;
}

function getArticle($uid)
{
    $objType = '1';
    $maxCounterId = getMaxCounterId('articles_id');
    $uid36Str = uidToStr36($uid);
    return $maxCounterId . '0' . $objType . $uid36Str;
}

function getDiaryBookId($uid)
{
    $objType = 'a';
    $maxCounterId = getMaxCounterId('diary_book_id');
    $uid36Str = uidToStr36($uid);
    return $maxCounterId . '0' . $objType . $uid36Str;
}

function getMaxCounterId($id_counter_key)
{
    //$current_id = IdCounter::setInc($id_counter_key);
    $current_id = 23018;
    $current_id = base_convert(intval($current_id), 10, 36);
    return str_pad($current_id, 7, 0, STR_PAD_LEFT);
}

function uidToStr36($uid)
{
    $uid36 = base_convert(intval($uid), 10, 36);
    return str_pad($uid36, 7, 0, STR_PAD_LEFT);
}

function getObjType($obj_id)
{
    $type = substr($obj_id, 7, 2);
    if (strlen($type) == 2 && $type == '00') {
        $type = (string)intval($type);
    } else {
        $type = ltrim($type, '0');
    }
    return $type;
}

var_dump('验证UserPortraitApi::request');
//\Doraemon\service\Live\LiveRoom::getPopInfo
var_dump('LiveRoom::getPopInfo');
$arr = [];
$uid = 1582647;
$userProfile = PositionApi::getOneUserProfile($uid, ['product_tag_1m']);
$arr[] = $userProfile;
$userProfile = UserPortraitApi::request($uid, ['product_tag_1m', 'uid'], UserPortraitApi::DEFAULT_TOKEN);
$arr[] = $userProfile;
var_dump($arr);

//Ranking::getRankingIdsByUserAction
var_dump('Ranking::getRankingIdsByUserAction');
$arr = [];
$uid = 1582647;
$cache = UserProfile::getItem($uid, ['recommend_brand_cate_30d']);
$arr[] = $cache;
$cache = UserPortraitApi::requestFromBrand($uid, ['recommend_brand_cate_30d']);
$arr[] = $cache;
var_dump($arr);

///data/wwwroot/g_biz/cli/Store/search.php
var_dump('data/wwwroot/g_biz/cli/Store/search.php');
$arr = [];
$uid = 1582647;
$userprofile = \Doraemon\cache\PositionModule\UserProfile::getItem($uid, ['area']);
$arr[] = $userProfile;
$userprofile = UserPortraitApi::requestFromBrand($uid, ['area']);
$arr[] = $userProfile;
var_dump($arr);

//\Doraemon\service\Lottery\LotteryRule\WIkiLottery::getBallNumByUid
var_dump('WIkiLottery::getBallNumByUid');
$arr = [];
$uid = 1582647;
$userProfile = PositionApi::getOneUserProfile($uid, ['user_type', 'auth_tag', 'quality', 'action_count_fans', 'last_login_day']);
$arr[] = $userProfile;
$userProfile = UserPortraitApi::requestFromService($uid, ['uid', 'user_type', 'auth_tag', 'quality', 'action_count_fans', 'last_login_day']);
$arr[] = $userProfile;
var_dump($arr);

//\Doraemon\service\Lottery\LotteryRule\JdLottery::getBallNumByUid
var_dump('JdLottery::getBallNumByUid');
$arr = [];
$uid = 1582647;
$userProfile = PositionApi::getOneUserProfile($uid, ['user_type', 'auth_tag', 'quality', 'action_count_fans', 'last_login_day']);
var_dump($userProfile);
$arr[] = $userProfile;
$userProfile = UserPortraitApi::requestFromService($uid, ['uid', 'user_type', 'auth_tag', 'quality', 'action_count_fans', 'last_login_day']);
$arr[] = $userProfile;
var_dump($arr);

//\Biz\tools\Location::_getUserLocationInfo
var_dump('Location::_getUserLocationInfo');
$arr = [];
$uid = 1582647;
$userProfile = PositionApi::getOneUserProfile($uid, ['city_name', 'city_id', 'longitude', 'latitude']);
$arr[] = $userProfile;
$userProfile = UserPortraitApi::requestFromBrand($uid, ['city_name', 'city_id', 'longitude', 'latitude', 'uid']);
$arr[] = $userProfile;
var_dump($arr);

//\Biz\module\Classes\wiki\Infos::_getRecommendList
var_dump('Infos::_getRecommendList');
$arr = [];
$uid = 1582647;
$uidFollow = PositionApi::getOneUserProfile($uid, ['action_follow_uid_list']);
$arr[] = $uidFollow;
$uidFollow = UserPortraitApi::requestFromBrand($uid, ['uid', 'action_follow_uid_list']);
$arr[] = $uidFollow;
var_dump($arr);
die;


$ctrWhite = CtrWhite::getWhite();
var_dump(in_array('00007bp050013n8y', $ctrWhite));
die;


$startDay = '2022-07-03';
$endDay = '2022-07-10';
$middleDayTime = getMiddleDayTime($startDay, $endDay);
var_dump($middleDayTime);
function getMiddleDayTime($startDay, $endDay)
{
    $planDay = (strtotime($endDay) - strtotime($startDay)) / 86400;
    $planDay = floor($planDay);
    $middle = ceil($planDay / 2);
    $middleDayTime = strtotime($startDay) + $middle * 86400 - 1;
    var_dump($planDay, $middle, $middleDayTime, date('Y-m-d H:i:s', $middleDayTime));
    return $middleDayTime;
}

die;

$id = '0000p8b0500bonvw';
$type = IdParse::getType($id);
$uids[] = IdParse::getUid($id);
$userList = User::getBatchBasicUserInfo($uids);
var_dump($type, $uids, $userList);
die;


$ids = ['0009v1f0000bonr2', '0009v560000bonr2', '0009v550000bonr2'];

$res = AdPlan::getContent(1, 1582647);
var_dump($res);
die;


$res = AdPlan::getPlanIdByPlanFlowNo('CPM101UT1A1');
var_dump($res);
die;

$dateTime = date('Y-m-d H:i:s');
$priceData = [
    [
        "package" => "0",
        "package_name" => "智能推荐",
        "package_desc" => "智能匹配适合推荐的人群包",
        "original_price" => "20.00",
        "price" => "20.00",
        "count" => "50",
        "total_price" => "1000.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "0",
        "package_name" => "智能推荐",
        "package_desc" => "智能匹配适合推荐的人群包",
        "original_price" => "20.00",
        "price" => "18.00",
        "count" => "100",
        "total_price" => "1800.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "72",
        "package_name" => "家具标准包",
        "package_desc" => "以家具类商品兴趣为标签的定向人群包",
        "original_price" => "30.00",
        "price" => "30.00",
        "count" => "50",
        "total_price" => "1500.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "72",
        "package_name" => "家具标准包",
        "package_desc" => "以家具类商品兴趣为标签的定向人群包",
        "original_price" => "30.00",
        "price" => "27.00",
        "count" => "100",
        "total_price" => "2700.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "73",
        "package_name" => "家具精准包",
        "package_desc" => "集合家具类商品兴趣及准备和正在装修状态为标签的定向人群包",
        "original_price" => "40.00",
        "price" => "40.00",
        "count" => "50",
        "total_price" => "2000.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "73",
        "package_name" => "家具精准包",
        "package_desc" => "集合家具类商品兴趣及准备和正在装修状态为标签的定向人群包",
        "original_price" => "40.00",
        "price" => "36.00",
        "count" => "100",
        "total_price" => "3600.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "74",
        "package_name" => "建材标准包",
        "package_desc" => "以建材类商品兴趣为标签的定向人群包",
        "original_price" => "50.00",
        "price" => "50.00",
        "count" => "50",
        "total_price" => "2500.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "74",
        "package_name" => "建材标准包",
        "package_desc" => "以建材类商品兴趣为标签的定向人群包",
        "original_price" => "50.00",
        "price" => "45.00",
        "count" => "100",
        "total_price" => "4500.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "75",
        "package_name" => "建材精准包",
        "package_desc" => "集合建材类商品兴趣及准备和正在装修状态为标签的定向人群包",
        "original_price" => "60.00",
        "price" => "60.00",
        "count" => "50",
        "total_price" => "3000.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ],
    [
        "package" => "75",
        "package_name" => "建材精准包",
        "package_desc" => "集合建材类商品兴趣及准备和正在装修状态为标签的定向人群包",
        "original_price" => "60.00",
        "price" => "54.00",
        "count" => "100",
        "total_price" => "5400.00",
        "create_time" => $dateTime,
        "update_time" => $dateTime
    ]
];
foreach ($priceData as $data) {
    mAdPrice::dataInsert($data);
}
die;

$planInfo = \Biz\model\bizAd\AdPlan::getPlanInfo(2);
var_dump(date('Y-m-d H:i:s', $planInfo['start_time']), date('Y-m-d H:i:s', $planInfo['end_time']));
list($startTime, $endTime, $settleTime) = AdPlan::getStartEndTime(
    date('Y-m-d', $planInfo['start_time']),
    date('Y-m-d', $planInfo['end_time'])
);
var_dump(date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', $endTime), date('Y-m-d H:i:s', $settleTime));
die;

$res = \Biz\service\bizAd\AdPlan::getContent(1, 19627214);
var_dump(json_encode($res));
$res = \Biz\service\bizAd\AdPlan::getContent(2, 19627214);
var_dump(json_encode($res));
die;

$ids = ['000ncqw000015zgh', '000nd5900000at8z', '000nd4o000010b13'];
var_dump(\Doraemon\model\Photos::getAllList($ids));
die;

$startDate = '2022-06-10';
$endDate = '2022-06-16';
var_dump((strtotime($endDate) - strtotime($startDate)) / 86400);

$startTime = strtotime($startDate);
$startTime = time();

$endTime = $startTime + (strtotime($endDate) - strtotime($startDate) + 86400);
echo '开始时间:' . date('Y-m-d H:i:s', $startTime) . ',结束时间:' . date('Y-m-d H:i:s', $endTime);
die;

var_dump(abs(strtotime('2022-06-21') - strtotime('2022-06-20')));
die;


//修复 finished_num>total
$where = ['info_type' => 2, 'task_state' => 2, 'finished_num[>]' => Medoo::raw('`total`'), 'LIMIT' => [0, 20000]];
$arr = \Doraemon\model\Task\UserTaskInfo::select(['id', 'total', 'finished_num'], $where);
var_dump(\Doraemon\model\Task\UserTaskInfo::log());
var_dump(count($arr));
//die;
foreach ($arr as $row) {
    unset($where['LIMIT']);
    $where['id'] = $row['id'];
    \Doraemon\model\Task\UserTaskInfo::update(['finished_num' => $row['total']], $where);
    var_dump(\Doraemon\model\Task\UserTaskInfo::log());
}
die;


$url = 'https://gxb.mmstat.com/gxb.gif?t=https%3A%2F%2Fequity.tmall.com%2Ftm%3FagentId%3D1658535%26bc_fl_src%3Dtmall_market_llb_1_1823162%26llbPlatform%3D_pube%26llbOsd%3D1%26mm_unid%3D1_11165767_560501015e6d575406060150056f5353086656040b075e&v=4d21e3cd03b6&di=__IDFA__&dim=__IMEI__&oaid=__OAID__&bc_fl_src=tmall_market_llb_1_1823162&llbPlatform=_pubu&llbOsd=1&agentId=1658535';
$url = 'https://s.click.taobao.com/t?e=m%3D2%26s%3DxNe%2BIfTuJCJw4vFB6t2Z2ueEDrYVVa64yK8Cckff7TXLWlSKdGSYDvwtEBcXrNR%2F5x%2BIUlGKNpVTIV5JL6GupbuAKY72%2BtfJDjMc8s8yAWCvL5NRwr3Jt0VUjoeWqzb%2BCGsxm48e9hlswKaVTi05N1WT%2BC6oRq%2Fn1o9aeP6FjQT9Umq014SDk64c3xId4pcWTEhiDaWTkR7ZGL0GbiMMd6BniEC%2BBYvRdlFi%2FORzA%2Bn0U4%2BZ1ZT8dnvkQRh5SpYKttvJ9Z4G1Zg%3D&union_lens=lensId:TAPI@1654611505@2132e5f2_0ada_1813e87f072_343b@01';
//$url='https://shop105245874.taobao.com';
//$url='https://youdelong.tmall.com/shop/view_shop.htm';
//$url='https://item.taobao.com/item.htm?id=557899924619';
$res = BizUrl::getTbUrl($url);
var_dump(json_encode(['type' => 'link', 'link' => $res['open_app_link']]));
die;

$url = 'https://gxb.mmstat.com/gxb.gif?t=https%3A%2F%2Fequity.tmall.com%2Ftm%3FagentId%3D1658535%26bc_fl_src%3Dtmall_market_llb_1_1823162%26llbPlatform%3D_pube%26llbOsd%3D1%26mm_unid%3D1_11165767_560501015e6d575406060150056f5353086656040b075e&v=4d21e3cd03b6&di=__IDFA__&dim=__IMEI__&oaid=__OAID__&bc_fl_src=tmall_market_llb_1_1823162&llbPlatform=_pubu&llbOsd=1&agentId=1658535';
//$url='https://equity.tmall.com/tm?agentId=1658535&bc_fl_src=tmall_market_llb_1_1823162&llbPlatform=_pube&llbOsd=1&mm_unid=1_11165767_560501015e6d575406060150056f5353086656040b075e&v=4d21e3cd03b6&di=__IDFA__&dim=__IMEI__&oaid=__OAID__&bc_fl_src=tmall_market_llb_1_1823162&llbPlatform=_pubu&llbOsd=1&agentId=1658535';
//$url='https://detail.tmall.com/item.htm?spm=a224e.7913437.1.1823162&id=577458712615&scene=taobao_shop&_bind=true&bc_fl_src=tmall_market_llb_1_1823162&llbPlatform=pc&agentId=1658535&llbIsd=1&bxsign=llb0miCFFcuH0GZdKmG1nKmyipWrgaz30Gbe2G72ew5IHsnB%20u%20G1JqjBY9p42MEAlHQiTwvPSEHIi0g8JiOVuk3WXbbWlYUIr0cGc91uq7PBg=&ntfMsId=2bbb46a72a6af351bd4b760a01ccff0f&llbOsd=1&mm_unid=1_11165767_560501015e6d575406060150056f5353086656040b075e&jlogid=0614150340e92b9a';
$res = BizUrl::getTbUrl($url);
//var_dump($res);
var_dump(json_encode(['type' => 'link', 'link' => $res['open_app_link']]));
$res = $url ? 'niceliving://webview/normalscreen?protego=' . urlencode(base64_encode(json_encode(['url' => $url]))) : '';
var_dump(json_encode(['type' => 'link', 'link' => $res]));
die;


$url = \Biz\tools\JdUnion::tryGetItemUnionUrl(100036791858);
//$url = 'http://coupon.m.jd.com/coupons/show.action?key=08e9b6eb43dc40c6b37ccc501adebd7c&roleId=47864138&to=pro.m.jd.com/mall/active/f5jmc66UPnHLo5y2G4cx7ovamQN/index.html';
$res = BizUrl::getJdMUrl($url);
var_dump($res);
die;
//
//$res=Wiki::getWikiList([142858]);
//var_dump(json_encode($res));die;

$arr = [];
$url = 'https://detail.tmall.com/item.htm?id=674755703757';
$res = BizUrl::getTbUrl($url);
$arr[] = $res;
$url = 'http://coupon.m.jd.com/coupons/show.action?key=08e9b6eb43dc40c6b37ccc501adebd7c&roleId=47864138&to=pro.m.jd.com/mall/active/f5jmc66UPnHLo5y2G4cx7ovamQN/index.html';
$res = BizUrl::getJdCouponUrl($url);
$arr[] = $res;
$url = \Biz\tools\JdUnion::tryGetItemUnionUrl(10028337904804);
$res = BizUrl::getJdProductDetailUrl(10028337904804, $url);
$arr[] = $res;

$url = 'https://shop.m.jd.com/?shopId=10578211';
$res = BizUrl::getJdShopUrl(10578211, $url);
$arr[] = $res;
$url = 'https:\/\/s.click.taobao.com\/t?e=m%3D2%26s%3DFAuSKLBM%2BE1w4vFB6t2Z2ueEDrYVVa64yK8Cckff7TXLWlSKdGSYDsom4DOJ5uF18sviUM61dt1TIV5JL6GupbuAKY72%2BtfJDjMc8s8yAWCvL5NRwr3Jt0VUjoeWqzb%2BCGsxm48e9hlswKaVTi05NxdJE9H8%2BJh%2FaNdeFflTFnuMHuv7RoNv0YzeH%2FA0sTcbC%2BH8C2hMP55%2BcEHsqBzvtYWLhXkoGmYy%2BPDdcBxFtxi2BpYL8wLX%2Bq6oKpVHVDV6vRn9s5lIr3k%3D&union_lens=lensId:TAPI@1652502922@210483fa_0b15_180c0d983c0_47aa@01';
$url = 'https://item.taobao.com/item.htm?id=657378463787';
$url = 'https://youdelong.tmall.com/shop/view_shop.htm';
$res = BizUrl::getTbUrl($url);
$arr[] = $res;
var_dump(json_encode($arr));
die;

$res = \Biz\module\Classes\wiki\Wiki::getRandUserCoverImg(1);
var_dump($res);
$res = \Biz\module\Classes\wiki\Wiki::getRandUserCoverImg(3);
var_dump($res);
die;

$page = $argv[1] ?? 1;
$pageSize = 1000;
$list = mWiki::selectByWhere([
        'channel' => mWiki::CHANNEL_TAOBAO,
        'channel_spu_status' => mWiki::CHANNEL_SPU_STATUS_OFF,
        'ORDER' => ['id' => 'DESC'],
        'LIMIT' => [($page - 1) * $pageSize, $pageSize],
    ]
);
var_dump(mWiki::log(), count($list));
$itemIds = array_column($list, 'channel_spu_id');
$tbkList = TbkGoods::isTbkGoods($itemIds);
foreach ($list as $row) {
    if (isset($tbkList[$row['channel_spu_id']])) {
        var_dump('重新抓取淘宝客商品信息#wiki_id:' . $row['id'] . '#淘宝商品id:' . $row['channel_spu_id']);
        try {
            $res = AdmWiki::admReloadWiki($row, AdmWiki::RELOAD_WIKI_TBK);
            if ($res) {
                var_dump('重新抓取成功');
            }
        } catch (\Exception $e) {
            var_dump($e->getMessage());
        }
    }
}
die;

var_dump(TbkGoods::getCount());
die;

$res = \Biz\module\Classes\wiki\Wiki::getRandUserCoverImg(400);
var_dump($res);
die;

$objId = '00010i90100bon1x';
$noteIds = sArticle::getRelaNoteIds($objId);
var_dump($noteIds);
die;

$res = Wiki::getWikiByLink('https://detail.tmall.com/item.htm?id=672992996746&skuId=5018327714315');
var_dump($res);
die;

$shopClassifyRelateCateIds = sShopClassify::getShopClassifyCateIds();
$categoryCacheData = [];
foreach ($shopClassifyRelateCateIds as $classifyId => $cateIds) {
    \Doraemon\service\search\Schedule::buildWikiRankingCache($categoryCacheData, $classifyId, $cateIds);
}
var_dump(json_encode($categoryCacheData));
die;

var_dump(json_encode(\Biz\service\TodayNiceGoods\TodayNIceGoodsService::getTodayNiceGood()));
die;


$list = BrandShop::getShopList('', 415) ?: [];
var_dump(json_encode($list));
//判断门店权益
$list['list'] = array_values($list) ?: [];

die;

$a = ['style' => ['1', '2'], 'material' => ['实木', '铁'], 'brand' => '宜家'];

$b = ['style' => ['欧美', '现代'], 'material' => ['实木', '橡木']];
var_dump(array_merge($a, $b));
die;


$tagIds = \Biz\model\brand\Brand::select('tag_id', ['tag_id[>]' => 0]);
$tagList = \Doraemon\model\Tag::getTagsByIds($tagIds);
$moreArr = [];
$noArr = [];
$fileName = '品牌旧标签，匹配了多个新标签.xlsx';
$filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;
$fp = fopen($filePath, 'w');
fputcsv($fp, ['旧标签', '新标签']);

$fileName2 = '品牌旧标签，未匹配上新标签.xlsx';
$filePath2 = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName2;
$fp2 = fopen($filePath2, 'w');
fputcsv($fp2, ['旧标签']);

foreach ($tagList as $row) {
    $newTag = \Doraemon\model\NewTag\Tag::select(['id', 'tag', 'tag_alias', 'parent_id'], [
        'parent_id' => 818,
        'tag' => trim($row['tag']),
    ]);
    $count = count($newTag);
    if ($count == 1) {
        $newTag = array_shift($newTag);
        if (isset($newTag['tag']) && $newTag['tag']) {
            \Biz\model\brand\Brand::update(['tag' => $newTag['tag']], ['tag_id' => $row['id']]);
            var_dump(\Biz\model\brand\Brand::log());
        }
    }
    if ($count > 1) {
        $newTags = array_column($newTag, 'tag');
        $moreArr[] = [
            'old_tag_id' => $row['id'],
            'old_tag' => $row['tag'],
            'new_tag' => $newTags,
        ];
        $item = [
            $row['tag'],
            implode(',', $newTags)
        ];
        fputcsv($fp, $item);
    } else if (!$count) {
        $noArr[] = [
            'old_tag_id' => $row['id'],
            'old_tag' => $row['tag'],
            'new_tag' => array_column($newTag, 'tag'),
        ];
        $item = [
            $row['tag']
        ];
        fputcsv($fp2, $item);
    }
}
fclose($fp);
fclose($fp2);
var_dump('品牌旧标签，匹配了多个新标签', json_encode($moreArr));
var_dump('品牌旧标签，未匹配上新标签', json_encode($noArr));
die;

$wikiId = 7374;
$wikiInfos = $wikiId ? Wiki::getWikiBaseInfos([$wikiId]) : [];
$wikiInfo = $wikiInfos[$wikiId] ?? [];
var_dump($wikiInfo);
$statSign = '{"a":"app","mt":"wiki_middle","m":"wiki_middle-card","ps":{"brand_id":"0","act_from":"note_detail","obj_id":"0009uye0000boo7g","obj_type":"0"},"s":"list","ds":"primal","oi":7374,"ot":1202,"i":0}';
$wikiInfos = $wikiId ? Wiki::getWikiBaseInfos([$wikiId]) : [];
$wikiInfo = $wikiInfos[$wikiId] ?? [];
if ($statSign && !empty($wikiInfo) && $wikiInfo['channel'] == mWiki::CHANNEL_TAOBAO) {
    //mcn 2.0
    $statSignArr = json_decode($statSign, true);
    var_dump($statSignArr);
    $objId = $statSignArr ? getObjId($statSignArr) : '';
    $objType = $objId ? IdParse::getType($objId) : '';
    var_dump($objId, $objType);
    $relateList = $objId ? mObjRelateWiki::getByWhere([
        'obj_id' => $objId,
        'obj_type' => $objType,
        'wiki_id' => $wikiId,
        'status' => mObjRelateWiki::STATUS_NORMAL,
    ], ['obj_id']) : [];
    var_dump($relateList, mObjRelateWiki::log());
}
die;

function getObjId($statSignArr)
{
    $params = $statSignArr['ps'] ?? [];
    $objId = $params['obj_id'] ?? '';
    if (!$objId) {
        $objId = $params['relate_id'] ?? '';
    }
    return $objId;
}

$list = mWiki::select(['channel_brand' => Medoo::raw('DISTINCT(channel_brand)')]);
$fileName = 'wiki第三方品牌-' . date('YmdHis') . '.xlsx';
$filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;
$fp = fopen($filePath, 'w');
fputcsv($fp, ['第三方品牌']);

$list = [];
$page = 1;
$pageSize = 5000;
do {
    $list = mWiki::select(['channel_brand' => Medoo::raw('DISTINCT(channel_brand)')], [
        'LIMIT' => [($page - 1) * $pageSize, $pageSize]
    ]);
    foreach ($list as $row) {
        $item = [
            $row['channel_brand']
        ];
        fputcsv($fp, $item);
    }
    $page++;
} while ($list);
fclose($fp);

\Biz\tools\Mail::send(['tangyiwan@haohaozhu.com'], '第三方品牌', '第三方品牌', $filePath);

$a = ['id' => 0];
var_dump(array_filter($a));
die;

$item = cShopClassifies::getItem(815);
var_dump($item);
$item = admGetClassifyListByPIds([815], [mShopCategoryClassify::STATUS_NORMAL]);
var_dump($item);
die;
$classifyInfo = ShopClassify::quiltGetClassifyById(813);
var_dump($classifyInfo);
die;

function admGetClassifyListByPIds($parentIds = [0], $status = [
    mShopCategoryClassify::STATUS_NORMAL,
    mShopCategoryClassify::STATUS_HIDE
])
{
    $parentIds = array_filter($parentIds);
    if (!$parentIds) {
        $allClassifies = mShopCategoryClassify::getClassifyByPids([0]);
        $parentIds = $allClassifies ? array_column($allClassifies[0], 'id') : [];
    }
    $classifyList = $parentIds ? mShopCategoryClassify::getListByIds($parentIds, $status) : [];
    $chirldClassifies = $parentIds ? mShopCategoryClassify::getClassifyByPids($parentIds, $status) : [];

    $Rst = [];
    if ($classifyList && is_array($classifyList)) foreach ($classifyList as $parentId => $item) {
        $Rst[$parentId] = $item;
        if ($item['deep'] == mShopCategoryClassify::DEEP_FIRST_CLASSIFY) {
            $Rst[$parentId]['classifies'] = isset($chirldClassifies[$parentId]) ? admGetClassifyListByPIds(array_column($chirldClassifies[$parentId], 'id')) : [];
        } else if ($item['deep'] == mShopCategoryClassify::DEEP_SECOND_CLASSIFY) {
            $cateIds = $parentIds = [];
            if (isset($chirldClassifies[$parentId])) foreach ($chirldClassifies[$parentId] as $chirldClassify) {
                if ($chirldClassify['cate_id']) {
                    $cateIds[] = $chirldClassify['cate_id'];
                } else {
                    $parentIds[] = $chirldClassify['id'];
                }
            }
            $Rst[$parentId] = array_merge($Rst[$parentId], [
                'cate_list' => mCategory::selectCategorys($cateIds),
                'classifies' => $parentIds ? admGetClassifyListByPIds($parentIds) : []
            ]);
        } else if ($item['deep'] == mShopCategoryClassify::DEEP_THIRD_CLAORCATE) {
            $Rst[$parentId] = array_merge($Rst[$parentId], [
                'cate_list' => mCategory::selectCategorys(isset($chirldClassifies[$parentId]) ? array_column($chirldClassifies[$parentId], 'cate_id') : [])
            ]);
        }

    }

    return $Rst;
}

$res = ShopClassify::quiltGetClassifyByIds([831]);
var_dump($res);
die;

$statSign = basicStatSign::genStatSign(basicStatSign::MODULE_WIKI_DETAIL_GOODS_ALBUM, [
    basicStatSign::EXTEND_KEY_OBJ_ID => 1,
    basicStatSign::EXTEND_KEY_OBJ_TYPE => BlockType::TYPE_GOODS_ALBUM,
], ['wiki_id' => 17084]);
var_dump($statSign);
die;

$res = \Biz\service\wiki\FindWIkiService::getUserClassifyList(1582647);
var_dump(json_encode($res));
die;

$tags = CNewUserProfile::getOneWithField(1582647, ['action_interest_tag_goods']);
var_dump($tags);
die;


die;


var_dump(\Doraemon\tools\HhzEnv::isProduction());
die;


$result = Sms::sendSms(
    13521553395,
    ['reason' => '已到期，如您想重新获取账号权益，'],
    ['CnUnicom' => Sms::CHINA_UNICOM_CONFIG['temp_brand_expired'], 'aliyun' => Sms::TYPE_BRAND_EXPIRED],
    '86'
);
die;

$brandAccountMap = \Biz\service\brandAccount\BrandAccount::getAllByUids([5687299, 10995019]);
$brandAccountMap = array_column($brandAccountMap, null, 'uid');
var_dump($brandAccountMap);
die;


$orderInfo = \Biz\model\brand\BrandOrder::get('*', ['dsn' => '100136902043762']);
\Biz\service\BrandRights\BrandRightsAllService::_async_afterBrandOrder($orderInfo);


die;


//设计师带货-返佣链接表洗wiki
$page = 1;
$product_ids = [];
$count = 0;
do {
    $product_ids = \Doraemon\model\Peanut\RakeBackModel::select('product_id', ['LIMIT' => [($page - 1) * 200, 200]]);
    var_dump(count($product_ids));
    $wikiSpuIds = mWiki::selectByWhere(['channel' => 1, 'channel_spu_id' => $product_ids], 'channel_spu_id');
    $spuIds = array_diff($product_ids, $wikiSpuIds);
    $count += count($spuIds);
    foreach ($spuIds as $spuId) {
        $url = RealUrl::formatLink($spuId, 1);
        var_dump($url);
        \Biz\service\wiki\Wiki::getWikiByLink($url);
    }
    $page++;
} while ($product_ids);
var_dump($count);
die;


//$res=\Biz\tools\TbkUnion::tbkCouponConvert(648810036350);
//var_dump($res);
$res = \Biz\tools\TbkUnion::tbkTpwdCreate('https://s.click.taobao.com/t?e=m%3D2%26s%3DbYwYkO0rAWpw4vFB6t2Z2ueEDrYVVa64yK8Cckff7TXLWlSKdGSYDn3kUjz108DMxq3IhSJN6GRTIV5JL6GupbuAKY72%2BtfJDjMc8s8yAWCvL5NRwr3Jt0VUjoeWqzb%2BCGsxm48e9hlswKaVTi05Nz%2FLwAZ7pItagG1ssS9hVgOySbHmSI7wOmd1HQKKxkiFClCmfxnJ3htyKJIAdWSe4f7nyHmkoZi7LfXKPIAHWDs%2BaXHN11WLd0AoLkLLR4dAD2v56rwMxvXGJe8N%2FwNpGw%3D%3D&union_lens=lensId:TAPI@1642732154@2103f6f9_0872_17e7a776f64_2ae0@01	');
var_dump($res);
die;
//$res=\Biz\tools\TbkUnion::tbkItemInfo(661884299168);
//var_dump($res);
//$res=\Biz\tools\TbkUnion::getItemInfo(661884299168);
//var_dump($res);
//$res=\Biz\tools\TbkUnion::tbkOrderDetails(1,'2021-11-11 00:00:00','2021-11-11 02:00:00');
//var_dump($res);

$activityMaterialId = 20150318020009017;
$unionId = 'tmjznhjngzc';
$res = TbkUnion::TbkActivityInfoGet($activityMaterialId, TbkUnion::ADZONE_ID4, TbkUnion::PID4, 0, $unionId);
var_dump($res);
$res = TbkUnion::TbkSpreadGet($res['click_url']);
var_dump($res);
die;
$res = [];
$file = '/data/wwwroot/g_biz/cli/Fix/2021年度榜单-更新.xlsx';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file);
$sheetCount = $spreadsheet->getSheetCount();
$sheetNames = $spreadsheet->getSheetNames();
for ($index = 0; $index < $sheetCount; $index++) {
    $list = [];
    $spreadsheet->setActiveSheetIndex($index);
    $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
    $arr = [];
    if ($sheetData && is_array($sheetData)) {
        $i = 0;
        foreach ($sheetData as $i => $item) {
            // 前三行不做处理，第一行为商品表格介绍，第二行为商品表格标题，第三行为示例，第四行才为真实数据
            if ($i <= 1) {
                continue;
            }
            $nick = trim($item['F']);
            $uid = \Doraemon\service\User::getUidByNick($nick);
            $userInfo = \Doraemon\service\User::getBasicUserInfo($uid);
            $pics = array_filter([trim($item['G']), trim($item['H']), trim($item['I'])]);
            $basicId = trim($item['A']);
            $wikiId = mWiki::getByWhere(['basic_id' => $basicId, 'is_default' => 1], 'id');
            $wikiId = empty($wikiId) ? 0 : $wikiId;
            $list[] = [
                "basic_id" => $basicId,
                "wiki_id" => $wikiId,
                "ranking_name" => trim($item['B']),
                "title" => trim($item['C']),
                "show_cnt" => trim($item['D']),
                "community" => trim($item['E']),
                "uid" => $uid,
                "nick" => $nick,
                "avatar" => $userInfo ? $userInfo['avatar'] : '',
                "pics" => $pics,
                'statSign' => ''
            ];
        }
        $res[] = [
            'cate_name' => $sheetNames[$index],
            'list' => $list
        ];
    }
}
var_dump(json_encode($res));
die;

$list = \Doraemon\model\Category::getAllCategorys();
$list = array_column($list, null, 'id');
$data = [];
foreach ($list as $row) {
    $info = [
        //'id' => $row['id'],
        'first_cate_name' => '',
        'second_cate_name' => '',
        'third_cate_name' => '',
        'four_cate_name' => '',
        'first_category_id' => '',
        'second_category_id' => '',
        'third_category_id' => '',
        'four_category_id' => '',
        'deep' => $row['deep']
    ];
    if ($row['deep'] > 1) {
        switch ($row['deep']) {
            case 2:
                $firstInfo = $list[$row['father_id']];
                $info['first_category_id'] = $firstInfo['id'];
                $info['first_cate_name'] = $firstInfo['cate_name'];
                $info['second_category_id'] = $row['id'];
                $info['second_cate_name'] = $row['cate_name'];
                break;
            case 3:
                $scondInfo = $list[$row['father_id']];
                $firstInfo = $list[$scondInfo['father_id']];
                $info['first_category_id'] = $firstInfo['id'];
                $info['first_cate_name'] = $firstInfo['cate_name'];
                $info['second_category_id'] = $scondInfo['id'];
                $info['second_cate_name'] = $scondInfo['cate_name'];
                $info['third_category_id'] = $row['id'];
                $info['third_cate_name'] = $row['cate_name'];
                break;
            case 4:
                $thirdInfo = $list[$row['father_id']];
                $scondInfo = $list[$thirdInfo['father_id']];
                $firstInfo = $list[$scondInfo['father_id']];
                $info['first_category_id'] = $firstInfo['id'];
                $info['first_cate_name'] = $firstInfo['cate_name'];
                $info['second_category_id'] = $scondInfo['id'];
                $info['second_cate_name'] = $scondInfo['cate_name'];
                $info['third_category_id'] = $thirdInfo['id'];
                $info['third_cate_name'] = $thirdInfo['cate_name'];
                $info['four_category_id'] = $row['id'];
                $info['four_cate_name'] = $row['cate_name'];
                break;
        }
    } else {
        $info['first_category_id'] = $row['id'];
        $info['first_cate_name'] = $row['cate_name'];
    }
    $data[] = $info;
}
$title = ['一级分类名称', '二级分类名称', '三级分类名称', '四级分类名称', '一级分类ID', '二级分类ID', '三级分类ID', '四级分类ID', '级别'];

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$titCol = 'A';
foreach ($title as $key => $value) {
    // 单元格内容写入
    $sheet->setCellValue($titCol . '1', $value);
    $titCol++;
}
$sheet->getColumnDimension('A')->setWidth(15);
$sheet->getColumnDimension('B')->setWidth(15);
$sheet->getColumnDimension('C')->setWidth(15);
$sheet->getColumnDimension('D')->setWidth(15);
$sheet->getColumnDimension('E')->setWidth(15);
$sheet->getColumnDimension('F')->setWidth(15);
$sheet->getColumnDimension('G')->setWidth(15);
$sheet->getColumnDimension('H')->setWidth(15);
$row = 2; // 从第二行开始
foreach ($data as $item) {
    $dataCol = 'A';
    foreach ($item as $value) {
        // 单元格内容写入
        $sheet->setCellValue($dataCol . $row, $value);
        $dataCol++;
    }
    $row++;
}
$fileName = '全部分类' . '.xlsx';
$filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $fileName;
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $fileName . '"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($filePath);
var_dump('导出成功');

die;

$itemId = 631804467615;
$itemId = 656001906795;
$res = \Biz\tools\OneBound::getTaoBaoItemInfo($itemId, 1);
var_dump($res);
$res = \Biz\tools\OneBound::getTaoBaoItemDesc($itemId);

var_dump($res);
die;

$info = mWiki::getInfoByChannelSpu(1, '634076357571');
$res = \Biz\service\wiki\Wiki::getOpenOtherLink($info);
var_dump($res);
die;

$a = 'https://item.taobao.com/item.htm?id=634076357571';
//$a='https://item.taobao.com/item.htm?id=617794170596';
$res = \Biz\module\Classes\wiki\Wiki::getWikiByContent($a, 1);
//var_dump($res);
die;


$noteIds = ['000d7x400000xx6f'];
$res = \Biz\service\wiki\RelatePhoto::getWikiListByPhotoIds(['000000s050008m20']);
var_dump(json_encode($res));
die;
$res = \Biz\service\wiki\ObjRelateWiki::getWikiListByObjIds($noteIds, 1);
var_dump(json_encode($res));
die;

$str = 'eyJpZCI6ImdoXzZjOWU3MzM0ZmJmNiIsInBhdGgiOiJwYWdlc1wvZGV0YWlsXC9kZXRhaWw%2FZ2lkPTE0OTkwNiZzb3VyY2U9aGFvaGFvemh1JmZlZWRiYWNrPTE0OTkwNiJ9';
$a = base64_decode(urldecode($str));
$a = json_decode($a, true);
var_dump($a);
$str = 'eyJ1cmwiOiJodHRwczpcL1wvY3BzYXBpLnhpYW9taXlvdXBpbi5jb21cL2Nwc1wvbG9naW4%2Fc291cmNlPWhhb2hhb3podSZmZWVkYmFjaz0xMjU3NDImdG89aHR0cHMlM0ElMkYlMkZtLnhpYW9taXlvdXBpbi5jb20lMkZkZXRhaWwlM0ZnaWQlM0QxMjU3NDIlMjZvcGFwcCUzRDUmaGh6anVtcD0xIn0%3D';
$a = base64_decode(urldecode($str));
var_dump(json_decode($a, true));
die;
$spuId = 125742;
$params = http_build_query(['gid' => $spuId, 'source' => 'haohaozhu', 'feedback' => $spuId]);

$cps = "https://cpsapi.xiaomiyoupin.com/cps/login?";
$to = 'https://m.xiaomiyoupin.com/detail?gid=' . $spuId;
$toApp = 'https://m.xiaomiyoupin.com/detail?gid=' . $spuId . "&opapp=5";

$channel_url = $cps . http_build_query(['source' => 'haohaozhu', 'feedback' => $spuId, 'to' => $to]);
$channel_mini_url = "pages/detail/detail?" . $params;
$channel_app_url = $cps . http_build_query(['source' => 'haohaozhu', 'feedback' => $spuId, 'to' => $toApp, 'hhzjump' => 1]);
var_dump($channel_url, $channel_mini_url, $channel_app_url);
die;


$content = '27￥W1JCXwOGWqO￥ https://m.tb.cn/h.fTktYFw  光无垠意大利FLOS餐厅挑高客厅吊灯进口书房卧室轻奢复古欧式2097';
$content = 'https://detail.tmall.com/item.htm?id=637557936144';
$content = 'https://detail.tmall.com/item.htm?id=650348634133';
//$dingDanXiaGoodsInfo = DingDanXia::getTbkItemInfo(1, 650348634133);
//var_dump($dingDanXiaGoodsInfo);die;
var_dump(\Biz\tools\TbkUnion::createInviteUrl(1582647));
die;
$info = mWiki::getInfoByChannelSpu(1, 563503400458);
$res = \Biz\service\wiki\AdmWiki::admReloadWiki($info);
var_dump($res);
die;
var_dump(\Biz\tools\OneBound::getTaoBaoItemInfo(650348634133));
die;
var_dump(\Biz\tools\OneBound::getTaoBaoItemInfo(576018377200, 1));
die;

//$res=\Biz\service\wiki\AdmWiki::admReloadWiki($info);
$res = \Biz\module\Classes\wiki\Wiki::getWikiByContent($content, 1);
var_dump($res);
die;


//
//var_dump(\Biz\tools\TbkUnion::saveTbkScPublisherInfo('620032831e2991f9c2ee2f45a6a9e446852fhj2abb1e3ba157987527','1582647'));
//die;
//var_dump(\Biz\tools\TbkUnion::createAccessToken('ytyQksD5H5C0GKThuq9qfGVP5974867'));
//die;
var_dump(\Biz\tools\TbkUnion::createInviteUrl(1582647));
die;
$res = \Biz\module\Classes\wiki\Wiki::getWikiByContent($content, 1);
var_dump($res);
die;

/*$content='https://detail.tmall.com/item.htm?id=653943217859';
$res=\Biz\module\Classes\wiki\Wiki::getWikiByContent($content);
var_dump($res);
die;*/
$content = 'https://item.taobao.com/item.htm?id=660409221987';
$res = \Biz\module\Classes\wiki\Wiki::getWikiByContent($content);
var_dump($res);
die;
$info = mWiki::getInfoByChannelSpu(1, 653943217859);
$res = \Biz\service\wiki\AdmWiki::admReloadWiki($info);
var_dump($res);
die;


$channelSpuId = [
    661966932322,
    543322004227,
    543346461376,
    543366291734,
    544823074683,
    547813466274,
    547846543967,
    551523440510,
    552827358792,
    558830784233,
    559405085342,
    560382503192,
    560413479253,
    561116256106,
    562001400896,
    562149353070,
    562244403918,
    564809392687,
    569558043573,
    569879758901,
    571173096852,
    571409254645,
    573918109593,
    574265461662,
    577698201289,
    577853361199,
    579639393648,
    581592037503,
    582545533540,
    583438876731,
    583522866828,
    583661415705,
    589814502886,
    591236023573,
    591629197652,
    591778454137,
    591917632409,
    592509324015,
    594109546932,
    595143149677,
    597178450891,
    597671382372,
    601345985985,
    601549762336,
    606286100749,
    606621847251,
    606981448079,
    607087044296,
    609509705257,
    611868979209,
    616267813669,
    617458531445,
    617900684509,
    617904240941,
    618457842955,
    618460794696,
    618716811699,
    619314895415,
    622759384265,
    622791708945,
    623453802349,
    623514106725,
    623674760995,
    623776127196,
    624789115457,
    624948905182,
    625463748759,
    627650814859,
    627910940899,
    630489170674,
    633264718517,
    635510331716,
    637746330514,
    639758649302,
    640092934609,
    642720138567,
    643638956614,
    643640544040,
    644379474143,
    646785516601,
    647192349581,
    647638547733,
    653035570498,
    655426880622,
    655429416627,
    656255713742,
    656307330157,
    659616965587,
    661966932322,
];

$list = mWiki::selectByWhere(['brand_id' => 359, 'channel_spu_id' => $channelSpuId, 'is_official' => 1]);
var_dump(count($list));
foreach ($list as $row) {
    var_dump(date('YmdH:i:s') . '开始同步wiki#wiki_id:' . $row['id']);
    $wikiInfo = \Biz\service\wiki\AdmWiki::admReloadWiki($row);
}
die;


$url = ImgUrl::getBizOriginUrl('0302521pc0yi0dX00qzjggi41mmf');
var_dump($url);
die;

$time = date("Y-m-d", strtotime("-10 day"));
$wikiList = mWiki::selectByWhere(['status' => mWiki::STATUS_NORMAL, 'channel' => 1, 'addtime[>=]' => $time, 'ORDER' => ['id' => 'ASC']]);
foreach ($wikiList as $row) {
    $contentInfo = \Biz\model\wiki\WikiContent::getByWhere(['wiki_id' => $row['id']], ['wiki_id', 'imgs', 'content']);
    $row['imgs'] = $contentInfo ? $contentInfo['imgs'] : '';
    $row['content'] = $contentInfo ? $contentInfo['content'] : '';
    if (!$row['title'] || !$row['cover_img']
        || (!$row['channel_shop_id'] && !$row['channel_seller_id'])
        || !$row['channel_shop_name']
        || $row['min_price'] <= 0 || $row['max_price'] <= 0
        || !$row['imgs'] || !$row['content']) {
        $result = clsWiki::updateByOneBound($row);
        var_dump($result);
    } else {
        var_dump('已完善商品信息#wiki_id:' . $row['id']);
        mWiki::updateData(['status' => mWiki::STATUS_WAIT_CHECK], ['id' => $row['id'], 'status' => mWiki::STATUS_NORMAL]);
    }
}
die;


$content = 'https://detail.tmall.com/item.htm?id=581088361435&sku_properties=21433:10122';
list($scraperWikiInfo, $itemId, $channelType) = scraperGoodsInfo::getGoodsInfo($content);
var_dump($scraperWikiInfo, $itemId, $channelType);

die;
$info = mWiki::getInfoByWikiId(142865);
$res = \Biz\service\wiki\AdmWiki::admReloadWiki($info);
var_dump($res);
die;
$res = \Biz\service\wiki\Wiki::getWikiByLink($content);
var_dump($res);
die;

//$content='https://detail.tmall.com/item.htm?id=653943217859&spm=a21bo.jianhua.201876.3.5af911d9HR93sY&scm=1007.34127.227518.0&pvid=b5b4e885-2c3a-4785-8f37-0900eb690ea1';
//$content='https://detail.tmall.com/item.htm?id=564111445463';
//$content='https://item.taobao.com/item.htm?id=564111445463';
$content = '67，多天也着他去看地得你要啊 https://m.tb.cn/h.f7yuKqA?sm=44014d  星巴克2021野营系列第二波康迪克合作款吸管杯野餐小熊夜灯玻璃杯';
$url = RealUrl::regexUrl($content);

preg_match('#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#iS', $content, $match);
var_dump($match);
die;

var_dump($url);
$res = RealUrl::getRealUrl($url);
var_dump($res);
die;
die;
$res = \Biz\scraper\GoodsInfo::getUrl($content);
var_dump($res);
die;
$res = \Biz\service\wiki\Wiki::getWikiByLink($content);
var_dump($res);
die;
$info = mWiki::getInfoByWikiId(142846);
$res = \Biz\service\wiki\AdmWiki::admReloadWiki($info);
var_dump($res);
die;
var_dump($res);
die;


//die;
//上线再执行
$res = mCustomCategoryWiki::select(['brand_id'], [
    'GROUP' => ['brand_id'],
    'category_id' => 0
]);
$brandIds = array_column($res, 'brand_id');
$brandIds = array_filter($brandIds);
var_dump($brandIds);
foreach ($brandIds as $brandId) {
    $where = [
        'brand_id' => $brandId,
        'custom_state' => mCustomCategoryWiki::STATE_NORMAL,
        'category_id' => 0,
        'ORDER' => ['sort' => 'ASC', 'id' => 'DESC'],
        'LIMIT' => [20, 100000],
    ];
    $delIds = mCustomCategoryWiki::selectByWhere($where, 'id');
    if ($delIds) {
        var_dump('delids:', $delIds . '#brand_id:' . $brandId);
        mCustomCategoryWiki::updateData(['custom_state' => mCustomCategoryWiki::STATE_DEL], ['id' => $delIds, 'brand_id' => $brandId, 'category_id' => 0, 'custom_state' => mCustomCategoryWiki::STATE_NORMAL]);
        var_dump(mCustomCategoryWiki::log());
    }
}
die;

$itemIds = [100022883702, 10028619247315, 100020844550, 10024268550039];
$res = \Biz\module\Classes\wiki\Wiki::getJdUnionLink($itemIds);
var_dump($res);
$wikiIds = [185939, 185938, 185937, 185940, 185941];
$infos = \Biz\service\wiki\Wiki::getWikiList($wikiIds);
//$infos = \Biz\module\Classes\wiki\Wiki::getWikiBaseInfos($wikiIds);
//$infos = \Biz\module\Classes\wiki\Wiki::get3rdInfos($infos);
var_dump($infos);
die;


$info = mWiki::getInfoByWikiId(142845);
\Biz\service\wiki\AdmWiki::admReloadWiki($info);
die;

$title = '日用神奇';
$arr = [
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918993.18bd1207d5JWmZ&id=636993236523&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=645828178298&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?&id=649068744023&spm=a1z0k.7385961.1997985097.d4918993.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=632658726751&spm=a1z0k.7385961.1997985097.d4918993.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=596386482497&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111&skuId=4142394664531',
    'https://detail.tmall.com/item.htm?id=649661577815&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=600047325715&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111&sku_properties=20397:494072105',
    'https://detail.tmall.com/item.htm?id=646042245644&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=595035758151&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=643722070401&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=618835179072&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=628245975475&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111&sku_properties=132348060:308806009;252675422:113313;256291250:7558738',
    'https://detail.tmall.com/item.htm?id=634956135167&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=645633631249&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=613390885592&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=658833568300&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=652086544764&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=604675663460&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=649877404606&spm=a1z0k.7385961.1997985097.d4918993.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=637523024630&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=599122328394&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://chaoshi.detail.tmall.com/item.htm?id=601639813316&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=615903827144&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=606165677415&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=655460082426&spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=651605648504&spm=a1z0k.7385961.1997985097.d4918993.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=601462451240&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=38912708161&_u=t2dmg8j26111',
    'https://detail.tmall.hk/hk/item.htm?id=610143056090&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=551594498551&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=644347182220&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=639716558974&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=652454049258&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=656278949616&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=536825279216&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=606336478780&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=574442282529&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=534925478259&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111&sku_properties=134942334:109101',
    'https://detail.tmall.com/item.htm?id=643330867509&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.0.d4919233.50311207EUAZhK&id=592129510861&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=577481294722&spm=a1z0k.7386009.0.0.3e7d1207woEiPu&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=574461169117&spm=a1z0k.7386009.0.0.3e7d1207woEiPu&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7628869.0.d4919233.58351207IIyk4n&id=616721104489&_u=t2dmg8j26111',
];
var_dump($title . '数量:' . count($arr));
report($title, $arr);

$title = '萌萌萌萌';
$arr = [
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&id=562775569322&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=591605195902&spm=a1z0k.7385961.1997985097.d4918993.18bd1207d5JWmZ&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918993.18bd1207d5JWmZ&id=647068179447&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&id=596316052306&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&id=653316701873&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?spm=a220o.1000855.1998025129.1.44c93ad8mOvFor&id=601472637470&scm=1007.12144.95220.23864_0_0&pvid=92984fa3-9230-4952-9e83-d7ff29b74df9&utparam=%7B%22x_hestia_source%22:%2223864%22,%22x_object_type%22:%22item%22,%22x_hestia_subsource%22:%22default%22,%22x_mt%22:0,%22x_src%22:%2223864%22,%22x_pos%22:1,%22wh_pid%22:-1,%22x_pvid%22:%2292984fa3-9230-4952-9e83-d7ff29b74df9%22,%22scm%22:%221007.12144.95220.23864_0_0%22,%22x_object_id%22:601472637470%7D&skuId=4680342647076',
    'https://detail.tmall.com/item.htm?id=635811027230&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=584855040721&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=657615037070&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=656153583997&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=654934228593&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=579566032140&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=656942979602&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=597693469343&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=607625882953&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=656791573257&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=637247583403&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=657960491930&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=592663289956&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=653509214905&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=655497447888&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=649682393008&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=565294451435&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=654760345652&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7628869.1997985097.d4918997.58351207IIyk4n&id=637676891151&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a230r.1.14.13.311a51afs4ZbdG&id=585910563713&ns=1&abbucket=12#detail',
];
var_dump($title . '数量:' . count($arr));
report($title, $arr);

$title = '设计好物';
$arr = [
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918993.18bd1207d5JWmZ&id=651160460280&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&id=629324915352&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.18bd1207d5JWmZ&id=593903039442&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=628075079949&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=563126987140&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111&sku_properties=3064956:9115665',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=567515118740&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=630260922518&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=577203988554&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=654401090103&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=543255335560&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918993.50311207EUAZhK&id=621737728822&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=642623147481&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=633155214152&_u=t2dmg8j26111',
    'https://detail.tmall.com/item.htm?id=645102442111&spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&_u=t2dmg8j26111&sku_properties=29112:97926',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=628110124534&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=628510086588&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=658566923513&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=573147638113&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=620771260637&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.50311207EUAZhK&id=603193244890&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7385961.0.d4919233.50311207EUAZhK&id=604459808857&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7386009.0.d4919233.3e7d1207woEiPu&id=643192261663&_u=t2dmg8j26111',
    'https://item.taobao.com/item.htm?spm=a1z0k.7628869.0.d4919233.58351207IIyk4n&id=629386022161&_u=t2dmg8j26111',
];
var_dump($title . '数量:' . count($arr));
report($title, $arr);
die;

function report($fileTitle, $arr)
{
    $data = [];
    foreach ($arr as $row) {
        $wikiInfo = \Biz\service\wiki\Wiki::getWikiByLink($row);
        $data[] = [
            'wiki_id' => $wikiInfo ? $wikiInfo['id'] : '',
            'basic_id' => $wikiInfo ? $wikiInfo['basic_id'] : '',
            'title' => $wikiInfo ? $wikiInfo['title'] : '',
            'url' => $row
        ];
    }
    $title = ['商品ID', 'WIKI ID', '商品名称', '商品链接'];

    $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
    $sheet = $spreadsheet->getActiveSheet();
    $titCol = 'A';
    foreach ($title as $key => $value) {
        // 单元格内容写入
        $sheet->setCellValue($titCol . '1', $value);
        $titCol++;
    }
    $sheet->getColumnDimension('A')->setWidth(15);
    $sheet->getColumnDimension('B')->setWidth(15);
    $sheet->getColumnDimension('C')->setWidth(30);
    $sheet->getColumnDimension('D')->setWidth(50);
    $row = 2; // 从第二行开始
    foreach ($data as $item) {
        $dataCol = 'A';
        foreach ($item as $value) {
            // 单元格内容写入
            $sheet->setCellValue($dataCol . $row, $value);
            $dataCol++;
        }
        $row++;
    }
    $fileName = $fileTitle . '.xlsx';
    $filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $fileName;
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="' . $fileName . '"');
    header('Cache-Control: max-age=0');
    header('Cache-Control: max-age=1');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
    header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header('Pragma: public'); // HTTP/1.0
    $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
    $writer->save($filePath);
    var_dump($fileTitle . '导出成功');
}

//$sign = [
//    'obj_type' => 1,
//    'obj_id' => null
//];
//$content='https://detail.tmall.com/item.htm?id=611812348231';
//scraperGoodsInfo::addTask($sign, $content, TaskCallbackInitWiki::class);

$content = 'https://detail.tmall.com/item.htm?spm=a220o.1000855.w4023-18797283509.4.b56e6a7bjYaU6N&id=612081705485&skuId=4308142728568';
$content = 'https://detail.tmall.com/item.htm?spm=a220o.1000855.w4023-18797283509.16.b56e6a7bjYaU6N&id=603196666737&sku_properties=21433:20629407';
$res = \Biz\service\wiki\Wiki::getWikiByLink($content);
var_dump($res);
die;

$res = \Doraemon\service\Task\Task::getTaskList(1582647, \Doraemon\model\Task\TaskGroup::CHANNEL_CREATORS, false, [\Doraemon\model\Task\TaskGroup::CYCLE_TYPE_DAY, \Doraemon\model\Task\TaskGroup::CYCLE_TYPE_LIMIT_TIME]);
var_dump(json_encode($res));
die;

$res = \Doraemon\service\Task\Task::getTaskListByTaskIds(1582647, [154, 153, 155, 171, 172, 173]);
var_dump(json_encode($res));
die;

$url = 'https://item.taobao.com/item.htm?id=615901054949';
//$url='https://item.taobao.com/item.htm?spm=a21bo.jianhua.201876.2.5af911d92oLhtH&id=652098222051&scm=1007.34127.211940.0&pvid=b10aa0ce-2add-467e-aab4-3300f64c7dcb';
$url = 'https://item.taobao.com/item.htm?id=608817360947';
$url = 'https://item.taobao.com/item.htm?id=609489544694';
$url = 'https://item.taobao.com/item.htm?id=560544033741';
//$res=\Biz\scraper\GoodsInfo::getGoodsInfo($url);
$res = \Biz\service\wiki\Wiki::getWikiByLink($url);
var_dump($res);
die;


$file = '/tmp/offlineTaobaoGoods.xlsx';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
$arr = [];
if ($sheetData && is_array($sheetData)) {
    $i = 0;
    foreach ($sheetData as $i => $item) {
        // 前三行不做处理，第一行为商品表格介绍，第二行为商品表格标题，第三行为示例，第四行才为真实数据
        if ($i <= 1) {
            continue;
        }
        $info = [
            "channel_spu_id" => (string)trim($item['A']),
            "channel_spu_status" => (string)trim($item['B']),
            "channel_type" => trim($item['E']),
        ];
//        if (!empty($info['channel_spu_id']) && $info['channel_spu_id'] > 0 && $info['channel_spu_status'] == 'N') {
//            $where = ['channel_spu_id' => $info['channel_spu_id'], 'channel' => mWiki::CHANNEL_TAOBAO];
//            $data = ['channel_spu_status' => 0];
//            if (!empty($info['channel_type'])) {
//                $data['channel_type'] = ($info['channel_type'] == 'B') ? mWiki::CHANNEL_TYPE_TMALL : mWiki::CHANNEL_TYPE_TAOBAO;
//            }
//            mWiki::update($data, $where);
//            var_dump(mWiki::log());
//            $i++;
//        }
        if (!empty($info['channel_spu_id']) && $info['channel_spu_id'] > 0 && $info['channel_spu_status'] == 'Y') {
            if (!empty($info['channel_type'])) {
                $channelType = ($info['channel_type'] == 'B') ? mWiki::CHANNEL_TYPE_TMALL : mWiki::CHANNEL_TYPE_TAOBAO;
                $data['channel_type'] = $channelType;
                $where = [
                    'channel_spu_id' => $info['channel_spu_id'],
                    'channel' => mWiki::CHANNEL_TAOBAO,
                    'channel_type[!]' => $channelType
                ];
                mWiki::update($data, $where);
                var_dump(mWiki::log());
                $i++;
            }
        }
    }
    var_dump('更新了' . $i . '条数据');
}

function repairWikiRanking()
{
    //修复被删除的榜单，todo 连续上榜，需要单独处理
    $ranking_day = 20220720;
    $rankingId = 46;
    $res = WikiRankingHot::select('*', ['ranking_day' => $ranking_day, 'ranking_id' => $rankingId, 'ORDER' => ['score' => 'DESC']]);
    $topNum = 1;
    foreach ($res as $row) {
        cacheWikiRanking::delHotCache($ranking_day, $row['basic_id']);
        $where = [
            'ranking_id' => $rankingId,
            'ranking_day' => $ranking_day,
            'basic_id' => $row['basic_id']
        ];
        $data = [
            'ranking_state' => WikiRankingHot::RANKING_STATE_SHOW,
            'top_num' => $topNum
        ];
        WikiRankingHot::updateData($data, $where);
        cacheWikiRanking::addBasicWikiHotRanking($ranking_day, $row['basic_id'], $topNum, $rankingId);
        $topNum++;
    }
    die;
}
